-
Notifications
You must be signed in to change notification settings - Fork 1
/
seed.js
146 lines (124 loc) · 3.92 KB
/
seed.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const connection = require("./config/mongoConnection");
const salesInquiry = require("./data/salesInquiry");
const usersData = require("./data/users");
const projectsData = require("./data/project");
const inventoryData = require("./data/inventory");
const casual = require("casual");
// generate 50 random inquiries with first name, last name, email, phone, subject and message
casual.define("user", function () {
return {
firstName: casual.first_name,
lastName: casual.last_name,
email: "",
phone: casual.numerify("##########"),
subject: casual.title,
message: casual.text,
};
});
let userArray = new Array();
for (let i = 0; i < 20; i++) {
const user = casual.user;
user.email = `${user.firstName.toLowerCase()}.${user.lastName.toLowerCase()}@gmail.com`;
userArray.push(user);
}
let sales1 = null;
let sales2 = null;
let customer1 = null;
let customer1inquiry = null;
async function main() {
const db = await connection.dbConnection();
await db.dropDatabase();
try {
for (let i = 0; i < userArray.length; i++) {
const inquiry = await salesInquiry.newInquiry(userArray[i].firstName, userArray[i].lastName, userArray[i].email, userArray[i].phone, userArray[i].subject, userArray[i].message);
console.log(inquiry);
}
} catch (error) {
console.log(error);
}
try {
const inquiry1 = await salesInquiry.newInquiry("Hem", "Patel", "[email protected]", "9871361803", "Solar Home Rooftop", "I want to install solar system");
console.log(inquiry1);
} catch (e) {
console.log(e);
}
try {
const inquiry2 = await salesInquiry.newInquiry("Jay", "Patel", "[email protected]", "9871361803", "Solar System", "I want to install solar system");
console.log(inquiry2);
} catch (e) {
console.log(e);
}
try {
sales1 = await usersData.createUser("Sales", "Account", "sales representative", "[email protected]", "7698654321", "Test@123");
console.log(sales1);
} catch (e) {
console.log(e);
}
try {
sales2 = await usersData.createUser("Salestwo", "Account", "sales representative", "[email protected]", "7698654321", "Test@123");
console.log(sales2);
} catch (e) {
console.log(e);
}
try {
const user2 = await usersData.createUser("Operations", "Account", "operational manager", "[email protected]", "7698654321", "Test@123");
console.log(user2);
} catch (e) {
console.log(e);
}
try {
const onsite = await usersData.createUser("Onsite", "Account", "onsite team", "[email protected]", "7698654321", "Test@123");
console.log(onsite);
} catch (e) {
console.log(e);
}
try {
const itAdmin1 = await usersData.createUser("ItAdmin", "Account", "it admin", "[email protected]", "7698654321", "Test@123");
console.log(itAdmin1);
} catch (e) {
console.log(e);
}
try {
customer1inquiry = await salesInquiry.newInquiry("customer", "Account", "[email protected]", "7698654321", "customer", "I want to install solar system");
} catch (e) {
console.log(e);
}
try {
customer1 = await usersData.createUser("customertwo", "Account", "customer", "[email protected]", "7698654321", "Test@123");
console.log(customer1);
} catch (e) {
console.log(e);
}
// try {
// const assignSalesRep = await salesInquiry.assignSalesRep(customer1inquiry._id, sales1._id);
// } catch (e) {
// console.log(e);
// }
try {
const inventory1 = await inventoryData.createNewInventory("Solar Panel", "892");
console.log(inventory1);
} catch (e) {
console.log(e);
}
try {
const inventory2 = await inventoryData.createNewInventory("Battery 15 kWh", "1263");
console.log(inventory2);
} catch (e) {
console.log(e);
}
try {
const inventory3 = await inventoryData.createNewInventory("Inverter", "275");
console.log(inventory3);
} catch (e) {
console.log(e);
}
// try {
// const update = await inventoryData.updateInventoryQuantity("6430e479e2e28496a79dba70", "500");
// console.log(update);
// } catch (e) {
// console.log(e);
// }
await connection.closeConnection();
console.log("Seed Executed");
}
main();