-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
35 lines (32 loc) · 1009 Bytes
/
data.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
const deleteUser = require("./routes/userRoutes/deleteUser");
const updateUser = require("./routes/userRoutes/updateUser");
// const createUser = require('./userRoutes/createUser');
// const getUser = require('./userRoutes/getUser');
// const listUsers = require('./userRoutes/listUsers');
// Массив для хранения пользователей
let users = []
let currentId = 1;
module.exports = {
getUsers: () => users,
addUser: (user) => {
user.id = currentId++;
users.push(user);
},
updateUser: (id, updatedData) => {
const userIndex = users.findIndex(u => u.id === id);
if (userIndex !== -1) {
users[userIndex] = { ...users[userIndex], ...updatedData};
return users[userIndex];
}
return null;
},
deleteUser: (id) => {
const userIndex = users.findIndex(u => u.id === id);
if (userIndex !== -1) {
users.splice(userIndex, 1);
return true;
}
return false;
},
getUserById: (id) => users.find(u => u.id === id)
};