-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
52 lines (44 loc) · 1.36 KB
/
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
46
47
48
49
50
51
52
const getUserIdByEmail = function(users, emailAccount) {
let confirmedUser;
for (let user in users) {
let usersEmail = users[user].email;
if (usersEmail === emailAccount) {
confirmedUser = users[user].id;
}
}
return confirmedUser;
};
const urlsForUser = function(database, id) {
const userURLDatabase = {};
for (let key in database) {
//target entries by user id
if (database[key].userID === id) {
// assign user specific objects to new object database
userURLDatabase[key] = database[key];
}
}
//return database
return userURLDatabase;
};
const confirmUserEmail = function(users, emailAccount) {
let confirmedEmail;
for (let user in users) {
let usersEmail = users[user].email;
if (usersEmail === emailAccount) {
confirmedEmail = users[user].email;
}
}
return confirmedEmail;
};
//generate random string for key names
const generateRandomString = function(lengthOfString) {
let characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let randomAlphaNum = '';
let randomString = '';
for (let i = 0; i < lengthOfString; i++) {
randomAlphaNum = (characters[(Math.floor(Math.random() * characters.length))]);
randomString += randomAlphaNum;
}
return randomString;
};
module.exports = { getUserIdByEmail, urlsForUser, confirmUserEmail, generateRandomString };