-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock-server.config.js
57 lines (52 loc) · 1.33 KB
/
mock-server.config.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
53
54
55
56
57
let users = [{ key: "1", name: "Aleksei Vavulo", age: 36, address: "Russia" }];
const findUserIndexByKey = (key) => users.findIndex((user) => user.key === key);
export const mockServerConfig = {
rest: {
baseUrl: "/api",
configs: [
{
path: "/users",
method: "get",
routes: [
{
data: () => users,
},
],
},
{
path: "/users",
method: "post",
routes: [
{
data: (req) => {
const newUser = req.body;
if (!newUser || !newUser.key) {
return { error: "Пользователь должен содержать ключ." };
}
users.push(newUser);
return newUser;
},
},
],
},
{
path: "/users/:key",
method: "delete",
routes: [
{
data: (req) => {
const { key } = req.params;
const userIndex = findUserIndexByKey(key);
if (userIndex === -1) {
return { error: "Пользователь не найден." };
}
users.splice(userIndex, 1);
return { success: true };
},
},
],
},
],
},
};
export default mockServerConfig;