-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeder.js
41 lines (37 loc) · 871 Bytes
/
seeder.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
40
41
import dotenv from "dotenv";
import { productData } from "./data/product.js";
import Product from "./models/Product.model.js";
import connectDB from "./startup/connectDB.js";
dotenv.config();
connectDB();
const importProduct = async () => {
try {
// creating user data us
for (let item of productData) {
await Product.create(item);
}
console.log("Data Imported!");
process.exit();
} catch (error) {
console.error(`${error}`);
process.exit(1);
}
};
const destroyData = async () => {
try {
console.log("Data Destroyed!");
process.exit();
} catch (error) {
console.error(`${error}`);
process.exit(1);
}
};
if (process.argv[2] === "-d") {
destroyData();
} else if (process.argv[2] === "product") {
importProduct();
} else if (process.argv[2] === "seller") {
importSeller();
} else {
importData();
}