-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImportData.js
39 lines (34 loc) · 1.12 KB
/
ImportData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import express from "express";
import expressAsyncHandler from "express-async-handler";
import User from "./models/UserModel.js";
import Product from "./models/ProductModel.js";
// import Category from "./models/Category.js";
import users from "./data/User.js";
import products from "./data/Products.js";
// import category from "./data/Category.js";
const ImportData = express.Router();
ImportData.post(
"/user",
expressAsyncHandler(async (req, res) => {
await User.deleteMany({});
const importUser = await User.insertMany(users);
res.send({ importUser });
})
);
ImportData.post(
"/product",
expressAsyncHandler(async (req, res) => {
await Product.deleteMany({});
const importProducts = await Product.insertMany(products);
res.send({ importProducts });
})
);
// ImportData.post(
// "/category",
// expressAsyncHandler(async (req, res) => {
// await Category.deleteMany({});
// const importCategory = await Category.insertMany(category);
// res.send({ importCategory });
// })
// );
export default ImportData;