-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create Fake Users Controller.txt
45 lines (38 loc) · 1.77 KB
/
Create Fake Users Controller.txt
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
const createFakeUsers = function(req, res) {
// This function will create 70 new users.
// It will be calling the registerFakeUser function above.
// This function is called AFTER we delete all users, see code below.
function create70Users() {
function create35Users(gender) {
for(let i = 0; i < 35; i++) {
let promise = new Promise(function(resolve, reject) {
registerFakeUser(gender, `${gender}${i + 1}`).then((val) => {
resolve(val);
});
});
promises.push(promise);
}
}
let promises = [];
create35Users("f");
create35Users("m");
return new Promise(function(resolve, reject) {
Promise.all(promises).then((val) => {
resolve(val);
});
});
}
// Before creating users, let's delete the current users.
let deleteUsers = new Promise(function(resolve, reject) {
User.deleteMany({ }, (err, info) => {
if(err) { reject(info); return res.send({ error: err }) }
resolve(info);
});
});
deleteUsers.then((val) => {
create70Users().then((val) => {
console.log(val);
res.statusJson(201, { message: "Created Fake Users" });
});
});
}