-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathfrank.js
More file actions
42 lines (34 loc) · 849 Bytes
/
Copy pathfrank.js
File metadata and controls
42 lines (34 loc) · 849 Bytes
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
const users = [
{ id: 1, name: 'Frank', email: 'efkidgamer@gmail.com', role: 'admin'}
];
function getUser(id) {
return users.find(user => user.id === id);
}
function getAllUsers() {
return users;
}
function addUser(user) {
const newId = users.length > 0 ? Math.max(...users.map(u => u.id)) + 1 : 1;
const newUser = { ...user, id: newId };
users.push(newUser);
return newUser;
}
function updateUser(id, updates) {
const index = users.findIndex(user => user.id === id);
if (index === -1) return null;
users[index] = { ...users[index], ...updates };
return users[index];
}
function deleteUser(id) {
const index = users.findIndex(user => user.id === id);
if (index === -1) return false;
users.splice(index, 1);
return true;
}
module.exports = {
getUser,
getAllUsers,
addUser,
updateUser,
deleteUser
};