-
Notifications
You must be signed in to change notification settings - Fork 1
/
seeder.js
50 lines (44 loc) · 1.25 KB
/
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
42
43
44
45
46
47
48
49
50
const connectDB = require("./env/db");
const User = require("./models/user-model");
const SupportMail = require("./models/supportmail-model");
const Admin = require("./models/admin-model");
const dotenv = require("dotenv");
const fs = require("fs");
dotenv.config({ path: "./env/config.env" });
// const user_data = JSON.parse(fs.readFileSync("./data/user-data.json", "utf-8"));
// const support_data = JSON.parse(
// fs.readFileSync("./data/support-data.json", "utf-8")
// );
const admin_data = JSON.parse(
fs.readFileSync("./data/admin-data.json", "utf-8")
);
connectDB();
const insertData = async () => {
try {
// await User.create(user_data);
// await SupportMail.create(support_data);
await Admin.create(admin_data);
console.log("Data insertion successful!");
} catch (error) {
console.error("Error inserting data:", error.message);
} finally {
process.exit();
}
};
const deleteData = async () => {
try {
// await User.deleteMany();
console.log("Data destroyed!");
// await SupportMail.deleteMany();
} catch (error) {
console.error("Error deleting data:", error.message);
} finally {
process.exit();
}
};
if (process.argv[2] === "-i") {
insertData();
}
if (process.argv[2] === "-d") {
deleteData();
}