@kne/fastify-account 1.0.0-alpha.10 → 1.0.0-alpha.12

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/README.md CHANGED
@@ -22,7 +22,7 @@ npm i --save @kne/fastify-account
22
22
  ### API
23
23
 
24
24
  ---
25
- title: "@kne/fastify-account v1.0.0-alpha.9"
25
+ title: "@kne/fastify-account v1.0.0-alpha.11"
26
26
  language_tabs:
27
27
  - shell: Shell
28
28
  - http: HTTP
@@ -42,7 +42,7 @@ headingLevel: 2
42
42
 
43
43
  <!-- Generator: Widdershins v4.0.1 -->
44
44
 
45
- <h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.9</h1>
45
+ <h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.11</h1>
46
46
 
47
47
  > Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.
48
48
 
@@ -87,19 +87,8 @@ fastify的用户管理账号等实现
87
87
  "type": "object",
88
88
  "properties": {
89
89
  "code": {
90
- "type": "number"
91
- },
92
- "data": {
93
- "type": "object",
94
- "properties": {
95
- "code": {
96
- "type": "string",
97
- "description": "验证码"
98
- }
99
- }
100
- },
101
- "msg": {
102
- "type": "string"
90
+ "type": "string",
91
+ "description": "验证码"
103
92
  }
104
93
  }
105
94
  }
@@ -117,10 +106,7 @@ Status Code **200**
117
106
 
118
107
  |Name|Type|Required|Restrictions|Description|
119
108
  |---|---|---|---|---|
120
- |» code|number|false|none|none|
121
- |» data|object|false|none|none|
122
- |»» code|string|false|none|验证码|
123
- |» msg|string|false|none|none|
109
+ |» code|string|false|none|验证码|
124
110
 
125
111
  <aside class="success">
126
112
  This operation does not require authentication
@@ -440,6 +426,48 @@ This operation does not require authentication
440
426
  This operation does not require authentication
441
427
  </aside>
442
428
 
429
+ ## post__api_v1_account_admin_setSuperAdmin
430
+
431
+ `POST /api/v1/account/admin/setSuperAdmin`
432
+
433
+ > Body parameter
434
+
435
+ ```json
436
+ {
437
+ "type": "object",
438
+ "required": [
439
+ "status",
440
+ "userId"
441
+ ],
442
+ "properties": {
443
+ "status": {
444
+ "type": "boolean"
445
+ },
446
+ "userId": {
447
+ "type": "string"
448
+ }
449
+ }
450
+ }
451
+ ```
452
+
453
+ <h3 id="post__api_v1_account_admin_setsuperadmin-parameters">Parameters</h3>
454
+
455
+ |Name|In|Type|Required|Description|
456
+ |---|---|---|---|---|
457
+ |body|body|object|true|none|
458
+ |» status|body|boolean|true|none|
459
+ |» userId|body|string|true|none|
460
+
461
+ <h3 id="post__api_v1_account_admin_setsuperadmin-responses">Responses</h3>
462
+
463
+ |Status|Meaning|Description|Schema|
464
+ |---|---|---|---|
465
+ |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
466
+
467
+ <aside class="success">
468
+ This operation does not require authentication
469
+ </aside>
470
+
443
471
  ## post__api_v1_account_admin_addUser
444
472
 
445
473
  `POST /api/v1/account/admin/addUser`
@@ -1997,6 +2025,28 @@ This operation does not require authentication
1997
2025
  This operation does not require authentication
1998
2026
  </aside>
1999
2027
 
2028
+ ## get__api_v1_account_tenant_getTenantUserList
2029
+
2030
+ `GET /api/v1/account/tenant/getTenantUserList`
2031
+
2032
+ <h3 id="get__api_v1_account_tenant_gettenantuserlist-parameters">Parameters</h3>
2033
+
2034
+ |Name|In|Type|Required|Description|
2035
+ |---|---|---|---|---|
2036
+ |filter|query|object|false|none|
2037
+ |currentPage|query|number|false|none|
2038
+ |perPage|query|number|false|none|
2039
+
2040
+ <h3 id="get__api_v1_account_tenant_gettenantuserlist-responses">Responses</h3>
2041
+
2042
+ |Status|Meaning|Description|Schema|
2043
+ |---|---|---|---|
2044
+ |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
2045
+
2046
+ <aside class="success">
2047
+ This operation does not require authentication
2048
+ </aside>
2049
+
2000
2050
  ## get__api_v1_account_tenant_orgList
2001
2051
 
2002
2052
  `GET /api/v1/account/tenant/orgList`
@@ -19,14 +19,7 @@ module.exports = fp(async (fastify, options) => {
19
19
  schema: {
20
20
  type: 'object',
21
21
  properties: {
22
- code: { type: 'number' },
23
- data: {
24
- type: 'object',
25
- properties: {
26
- code: { type: 'string', description: '验证码' }
27
- }
28
- },
29
- msg: { type: 'string' }
22
+ code: { type: 'string', description: '验证码' }
30
23
  }
31
24
  }
32
25
  }
@@ -9,7 +9,7 @@ module.exports = fp(async (fastify, options) => {
9
9
  onRequest: [authenticate.user]
10
10
  },
11
11
  async request => {
12
- await services.admin.initSuperAdmin(await services.user.getUser(request.authenticatePayload));
12
+ await services.admin.initSuperAdmin(request.userInfo);
13
13
  return {};
14
14
  }
15
15
  );
@@ -24,6 +24,28 @@ module.exports = fp(async (fastify, options) => {
24
24
  }
25
25
  );
26
26
 
27
+ fastify.post(
28
+ `${options.prefix}/admin/setSuperAdmin`,
29
+ {
30
+ onRequest: [authenticate.user, authenticate.admin],
31
+ schema: {
32
+ body: {
33
+ type: 'object',
34
+ required: ['status', 'userId'],
35
+ properties: {
36
+ status: { type: 'boolean' },
37
+ userId: { type: 'string' }
38
+ }
39
+ }
40
+ }
41
+ },
42
+ async request => {
43
+ const { status, userId } = request.body;
44
+ await services.admin[status ? 'setSuperAdmin' : 'cancelSuperAdmin'](await services.user.getUser({ id: userId }));
45
+ return {};
46
+ }
47
+ );
48
+
27
49
  fastify.post(
28
50
  `${options.prefix}/admin/addUser`,
29
51
  {
@@ -201,14 +201,30 @@ module.exports = fp(async (fastify, options) => {
201
201
  query: {
202
202
  type: 'object',
203
203
  properties: {
204
- tenantId: { type: 'string' }
204
+ tenantId: { type: 'string' },
205
+ filter: {
206
+ type: 'object',
207
+ properties: {
208
+ name: { type: 'string' }
209
+ }
210
+ },
211
+ currentPage: { type: 'number' },
212
+ perPage: { type: 'number' }
205
213
  }
206
214
  }
207
215
  }
208
216
  },
209
217
  async request => {
210
- const { tenantId } = request.query;
211
- return await services.tenantUser.getTenantUserList({ tenantId });
218
+ const { filter, tenantId, currentPage, perPage } = Object.assign(
219
+ {},
220
+ {
221
+ filter: {},
222
+ currentPage: 1,
223
+ perPage: 20
224
+ },
225
+ request.query
226
+ );
227
+ return await services.tenantUser.getTenantUserList({ tenantId, filter, currentPage, perPage });
212
228
  }
213
229
  );
214
230
 
@@ -21,6 +21,41 @@ module.exports = fp(async (fastify, options) => {
21
21
  }
22
22
  );
23
23
 
24
+ fastify.get(
25
+ `${options.prefix}/tenant/getTenantUserList`,
26
+ {
27
+ onRequest: [authenticate.user, authenticate.tenant],
28
+ schema: {
29
+ query: {
30
+ type: 'object',
31
+ properties: {
32
+ filter: {
33
+ type: 'object',
34
+ properties: {
35
+ name: { type: 'string' }
36
+ }
37
+ },
38
+ currentPage: { type: 'number' },
39
+ perPage: { type: 'number' }
40
+ }
41
+ }
42
+ }
43
+ },
44
+ async request => {
45
+ const { id: tenantId } = request.tenantInfo.tenant;
46
+ const { filter, currentPage, perPage } = Object.assign(
47
+ {},
48
+ {
49
+ filter: {},
50
+ currentPage: 1,
51
+ perPage: 20
52
+ },
53
+ request.query
54
+ );
55
+ return await services.tenantUser.getTenantUserList({ tenantId, currentPage, perPage, filter });
56
+ }
57
+ );
58
+
24
59
  fastify.get(
25
60
  `${options.prefix}/tenant/orgList`,
26
61
  {
@@ -2,7 +2,7 @@ const fp = require('fastify-plugin');
2
2
 
3
3
  const ROLE = {
4
4
  SuperAdmin: 'SuperAdmin',
5
- TenantAdmin: 'TenantAdmin'
5
+ Common: 'Common'
6
6
  };
7
7
 
8
8
  module.exports = fp(async (fastify, options) => {
@@ -41,7 +41,7 @@ module.exports = fp(async (fastify, options) => {
41
41
  };
42
42
 
43
43
  const setSuperAdmin = async targetUser => {
44
- const user = await services.user.getUserInfo(targetUser);
44
+ const user = await services.user.getUser(targetUser);
45
45
  if (
46
46
  (await models.adminRole.count({
47
47
  where: {
@@ -59,9 +59,30 @@ module.exports = fp(async (fastify, options) => {
59
59
  });
60
60
  };
61
61
 
62
- const generateTenantAdminVerifyCode = async () => {};
62
+ const cancelSuperAdmin = async targetUser => {
63
+ const user = await services.user.getUser(targetUser);
64
+ if (
65
+ !(await models.adminRole.count({
66
+ where: {
67
+ userId: user.id,
68
+ role: ROLE['SuperAdmin']
69
+ }
70
+ })) > 0
71
+ ) {
72
+ throw new Error('当前用户不是超级管理员');
73
+ }
63
74
 
64
- const verifyTenantAdmin = async () => {};
75
+ await models.adminRole.update(
76
+ {
77
+ role: ROLE['Common']
78
+ },
79
+ {
80
+ where: {
81
+ userId: user.id
82
+ }
83
+ }
84
+ );
85
+ };
65
86
 
66
87
  const resetUserPassword = async ({ userId, password }) => {
67
88
  await services.account.resetPassword({ userId, password });
@@ -70,9 +91,8 @@ module.exports = fp(async (fastify, options) => {
70
91
  services.admin = {
71
92
  initSuperAdmin,
72
93
  setSuperAdmin,
94
+ cancelSuperAdmin,
73
95
  checkIsSuperAdmin,
74
- generateTenantAdminVerifyCode,
75
- verifyTenantAdmin,
76
96
  addUser,
77
97
  resetUserPassword
78
98
  };
@@ -456,12 +456,23 @@ module.exports = fp(async (fastify, options) => {
456
456
  await tenantUser.save();
457
457
  };
458
458
 
459
- const getTenantUserList = async ({ tenantId }) => {
459
+ const getTenantUserList = async ({ tenantId, currentPage, perPage, filter }) => {
460
+ const queryFilter = {};
460
461
  await services.tenant.getTenant({ id: tenantId });
461
462
 
463
+ ['name', 'phone', 'email'].forEach(key => {
464
+ if (filter && filter[key]) {
465
+ queryFilter[key] = {
466
+ [Op.like]: `%${filter[key]}%`
467
+ };
468
+ }
469
+ });
470
+
462
471
  const { count, rows } = await fastify.account.models.tenantUser.findAndCountAll({
463
472
  include: [fastify.account.models.tenantRole, fastify.account.models.tenantOrg, fastify.account.models.user],
464
- where: { tenantId }
473
+ where: Object.assign({}, queryFilter, { tenantId }),
474
+ offset: currentPage * (currentPage - 1),
475
+ limit: perPage
465
476
  });
466
477
 
467
478
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-account",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.12",
4
4
  "description": "fastify的用户管理账号等实现",
5
5
  "main": "index.js",
6
6
  "scripts": {