-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
41 lines (36 loc) · 1.1 KB
/
database.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
exports.db = function () {
const data = {
users: [{
username: "[email protected]",
first: "Mark",
last: "Taylor"
},{
username: "[email protected]",
first: "Kenneth",
last: "Davis"
}]
}
return {
users: {
list: () => {
return data.users;
},
find: (username) => {
return data.users.filter((u) => u.username === username);
},
upsert: (user) => {
let userIndex = data.users.findIndex((u) => u.username === user.username);
if (data.users[userIndex]) {
data.users.splice(userIndex, 1);
}
data.users.push(user);
},
delete: (username) => {
let userIndex = data.users.findIndex((u) => u.username === username);
if (data.users[userIndex]) {
data.users.splice(userIndex, 1);
}
}
}
}
}