-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper Functions.txt
36 lines (28 loc) · 1.6 KB
/
Helper Functions.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
const getRandom = function(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
const registerFakeUser = function(gender, email) {
// Checks if you should use a female name or male name.
if(gender == "f") {
var firstName = femaleNames[getRandom(0, femaleNames.length - 1)];
} else {
var firstName = maleNames[getRandom(0, maleNames.length - 1)];
}
// The last name is independent of the users gender.
lastName = familyNames[getRandom(0, familyNames.length - 1)];
// This function will return a promise. The promise gets resolved when the user is saved successfully.
return new Promise(function(resolve, reject) {
// Create the user user
let user = new User();
user.name = firstName + " " + lastName;
user.email = email;
// The email follows the same pattern as the name of the images I am using. That's why I'm setting the profile_image to the, "email".
user.profile_image = email;
// All users have the same password, "f". It will allow us to log into any account we want.
user.setPassword("f");
user.save((err, user) => {
if(err) { reject(); return res.json({err: err}) }
resolve(user);
});
});
}