generated from lighthouse-labs/node-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.js
45 lines (42 loc) · 1023 Bytes
/
helpers.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
// USER DATABASE (TEMP)
const users = {
"userRandomID": {
id: "userRandomID",
email: "[email protected]",
password: "purple-monkey-dinosaur"
},
"user2RandomID": {
id: "user2RandomID",
email: "[email protected]",
password: "dishwasher-funk"
}
};
// HELPER FUNCTIONS
// Returns true if email exists
function checkEmailExists(email){
for(let key in users){
if(users[key].email===email){
return true;
}
}
return undefined;
}
// Returns entire user object if email matches an existing user
function matchingUser(email) {
for (let key in users) {
if(users[key].email === email) {
return users[key];
}
}
}
// Creates new Favourites object list by specific user ID
function getUserURLS(urlDatabase, id) {
let userURLS = {};
for (let key in urlDatabase) {
if (urlDatabase[key].userID === id) {
userURLS[key] = urlDatabase[key]; // adding new urls to urldatabase
}
}
return userURLS;
};
module.exports = { checkEmailExists, matchingUser };