@kne/fastify-account 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/controllers/admin-user.js +91 -91
- package/package.json +1 -1
|
@@ -1,110 +1,110 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
|
|
3
3
|
const adminUserController = fp(async (fastify, options) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
}
|
|
4
|
+
const { services, authenticate } = fastify[options.name];
|
|
5
|
+
fastify.get(`${options.prefix}/admin/getUserList`, {
|
|
6
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
7
|
+
tags: ['管理后台'], summary: '获取用户列表', query: {
|
|
8
|
+
type: 'object', properties: {
|
|
9
|
+
perPage: { type: 'number' }, currentPage: { type: 'number' }
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}, async request => {
|
|
14
|
+
const { filter, perPage, currentPage } = Object.assign({
|
|
15
|
+
perPage: 20, currentPage: 1
|
|
16
|
+
}, request.query);
|
|
17
|
+
return await services.user.getUserList({
|
|
18
|
+
filter, perPage, currentPage
|
|
20
19
|
});
|
|
20
|
+
});
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
22
|
+
fastify.post(`${options.prefix}/admin/resetUserPassword`, {
|
|
23
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
24
|
+
tags: ['管理后台'], summary: '重置用户账号密码', body: {
|
|
25
|
+
type: 'object', required: ['userId', 'password'], properties: {
|
|
26
|
+
password: { type: 'string' }, userId: { type: 'string' }
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, async request => {
|
|
31
|
+
await services.account.resetPassword(request.body);
|
|
32
|
+
return {};
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
fastify.post(`${options.prefix}/admin/addUser`, {
|
|
36
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
37
|
+
tags: ['管理后台'], summary: '添加用户', body: {}
|
|
38
|
+
}
|
|
39
|
+
}, async request => {
|
|
40
|
+
const userInfo = request.body;
|
|
41
|
+
await services.user.addUser(Object.assign({}, userInfo, {
|
|
42
|
+
status: 10, password: services.account.md5(options.defaultPassword)
|
|
43
|
+
}));
|
|
44
|
+
return {};
|
|
45
|
+
});
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}
|
|
47
|
+
fastify.post(`${options.prefix}/admin/saveUser`, {
|
|
48
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
49
|
+
tags: ['管理后台'], summary: '修改用户信息', body: {
|
|
50
|
+
type: 'object', required: ['id'], properties: {
|
|
51
|
+
id: { type: 'string' },
|
|
52
|
+
avatar: { type: 'string' },
|
|
53
|
+
nickname: { type: 'string' },
|
|
54
|
+
phone: { type: 'string', default: '' },
|
|
55
|
+
email: { type: 'string', default: '' },
|
|
56
|
+
description: { type: 'string', default: '' }
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, async request => {
|
|
61
|
+
const user = request.body;
|
|
62
|
+
await services.user.saveUser(user);
|
|
63
|
+
return {};
|
|
64
|
+
});
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
66
|
+
fastify.post(`${options.prefix}/admin/setSuperAdmin`, {
|
|
67
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
68
|
+
tags: ['管理后台'], summary: '设置用户为超级管理员', body: {
|
|
69
|
+
type: 'object', required: ['status', 'userId'], properties: {
|
|
70
|
+
status: { type: 'boolean', description: 'true:将用户设置为超级管理员,false:取消用户超级管理员' },
|
|
71
|
+
userId: { type: 'string', description: '用户id' }
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, async request => {
|
|
76
|
+
const { status, userId } = request.body;
|
|
77
|
+
await services.user.setSuperAdmin({ userId, status });
|
|
78
|
+
return {};
|
|
79
|
+
});
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
81
|
+
fastify.post(`${options.prefix}/admin/setUserClose`, {
|
|
82
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
83
|
+
tags: ['管理后台'], summary: '关闭用户', body: {
|
|
84
|
+
type: 'object', required: ['id'], properties: {
|
|
85
|
+
id: { type: 'string' }
|
|
88
86
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, async request => {
|
|
90
|
+
const { id } = request.body;
|
|
91
|
+
await services.user.setUserStatus({ userId: id, status: 12 });
|
|
92
|
+
return {};
|
|
93
|
+
});
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
95
|
+
fastify.post(`${options.prefix}/admin/setUserNormal`, {
|
|
96
|
+
onRequest: [authenticate.user, authenticate.admin], schema: {
|
|
97
|
+
tags: ['管理后台'], summary: '设置用户状态为正常', body: {
|
|
98
|
+
type: 'object', required: ['id'], properties: {
|
|
99
|
+
id: { type: 'string' }
|
|
102
100
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, async request => {
|
|
104
|
+
const { id } = request.body;
|
|
105
|
+
await services.user.setUserStatus({ userId: id, status: 0 });
|
|
106
|
+
return {};
|
|
107
|
+
});
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
module.exports = adminUserController;
|