@kne/fastify-account 1.0.0-alpha.1 → 1.0.0-alpha.11

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.
Files changed (42) hide show
  1. package/README.md +101 -5
  2. package/index.js +13 -4
  3. package/libs/controllers/account.js +9 -15
  4. package/libs/controllers/admin.js +38 -15
  5. package/libs/controllers/adminPermission.js +42 -35
  6. package/libs/controllers/adminRole.js +13 -12
  7. package/libs/controllers/adminTenant.js +39 -36
  8. package/libs/controllers/tenant.js +51 -4
  9. package/libs/controllers/user.js +23 -1
  10. package/libs/models/admin-role.js +4 -8
  11. package/libs/models/application.js +16 -10
  12. package/libs/models/login-log.js +4 -8
  13. package/libs/models/permission.js +7 -9
  14. package/libs/models/tenant-application.js +8 -10
  15. package/libs/models/tenant-org.js +5 -9
  16. package/libs/models/tenant-permission.js +7 -9
  17. package/libs/models/tenant-role-application.js +14 -10
  18. package/libs/models/tenant-role-permission.js +10 -9
  19. package/libs/models/tenant-role.js +5 -9
  20. package/libs/models/tenant-share-group-permission.js +5 -9
  21. package/libs/models/tenant-share-group.js +5 -9
  22. package/libs/models/tenant-source-user-share-group.js +5 -9
  23. package/libs/models/tenant-token.js +7 -9
  24. package/libs/models/tenant-user-org.js +11 -10
  25. package/libs/models/tenant-user-role.js +11 -10
  26. package/libs/models/tenant-user-share-group.js +6 -10
  27. package/libs/models/tenant-user.js +35 -16
  28. package/libs/models/tenant.js +17 -9
  29. package/libs/models/user-account.js +17 -9
  30. package/libs/models/user.js +27 -17
  31. package/libs/models/verification-code.js +4 -8
  32. package/libs/services/account.js +34 -16
  33. package/libs/services/admin.js +38 -122
  34. package/libs/services/application.js +151 -0
  35. package/libs/services/permission.js +47 -145
  36. package/libs/services/tenant-invite.js +62 -0
  37. package/libs/services/tenant-org.js +97 -0
  38. package/libs/services/tenant-role.js +108 -0
  39. package/libs/services/tenant-user.js +566 -0
  40. package/libs/services/tenant.js +68 -512
  41. package/libs/services/user.js +69 -30
  42. package/package.json +3 -3
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.0"
25
+ title: "@kne/fastify-account v1.0.0-alpha.10"
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.0</h1>
45
+ <h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.10</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
 
@@ -1008,6 +1008,45 @@ This operation does not require authentication
1008
1008
 
1009
1009
  `POST /api/v1/account/admin/saveTenantPermissionList`
1010
1010
 
1011
+ > Body parameter
1012
+
1013
+ ```json
1014
+ {
1015
+ "type": "object",
1016
+ "required": [
1017
+ "tenantId",
1018
+ "applications",
1019
+ "permissions"
1020
+ ],
1021
+ "properties": {
1022
+ "tenantId": {
1023
+ "type": "string"
1024
+ },
1025
+ "applications": {
1026
+ "type": "array",
1027
+ "items": {
1028
+ "type": "string"
1029
+ }
1030
+ },
1031
+ "permissions": {
1032
+ "type": "array",
1033
+ "items": {
1034
+ "type": "number"
1035
+ }
1036
+ }
1037
+ }
1038
+ }
1039
+ ```
1040
+
1041
+ <h3 id="post__api_v1_account_admin_savetenantpermissionlist-parameters">Parameters</h3>
1042
+
1043
+ |Name|In|Type|Required|Description|
1044
+ |---|---|---|---|---|
1045
+ |body|body|object|true|none|
1046
+ |» tenantId|body|string|true|none|
1047
+ |» applications|body|[string]|true|none|
1048
+ |» permissions|body|[number]|true|none|
1049
+
1011
1050
  <h3 id="post__api_v1_account_admin_savetenantpermissionlist-responses">Responses</h3>
1012
1051
 
1013
1052
  |Status|Meaning|Description|Schema|
@@ -1022,6 +1061,12 @@ This operation does not require authentication
1022
1061
 
1023
1062
  `GET /api/v1/account/admin/getTenantPermissionList`
1024
1063
 
1064
+ <h3 id="get__api_v1_account_admin_gettenantpermissionlist-parameters">Parameters</h3>
1065
+
1066
+ |Name|In|Type|Required|Description|
1067
+ |---|---|---|---|---|
1068
+ |tenantId|query|string|true|none|
1069
+
1025
1070
  <h3 id="get__api_v1_account_admin_gettenantpermissionlist-responses">Responses</h3>
1026
1071
 
1027
1072
  |Status|Meaning|Description|Schema|
@@ -1938,11 +1983,25 @@ This operation does not require authentication
1938
1983
  This operation does not require authentication
1939
1984
  </aside>
1940
1985
 
1941
- ## get__api_v1_account_tenant_getUserCurrentTenant
1986
+ ## get__api_v1_account_tenant_getTenantUserInfo
1987
+
1988
+ `GET /api/v1/account/tenant/getTenantUserInfo`
1989
+
1990
+ <h3 id="get__api_v1_account_tenant_gettenantuserinfo-responses">Responses</h3>
1991
+
1992
+ |Status|Meaning|Description|Schema|
1993
+ |---|---|---|---|
1994
+ |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
1995
+
1996
+ <aside class="success">
1997
+ This operation does not require authentication
1998
+ </aside>
1999
+
2000
+ ## get__api_v1_account_tenant_orgList
1942
2001
 
1943
- `GET /api/v1/account/tenant/getUserCurrentTenant`
2002
+ `GET /api/v1/account/tenant/orgList`
1944
2003
 
1945
- <h3 id="get__api_v1_account_tenant_getusercurrenttenant-responses">Responses</h3>
2004
+ <h3 id="get__api_v1_account_tenant_orglist-responses">Responses</h3>
1946
2005
 
1947
2006
  |Status|Meaning|Description|Schema|
1948
2007
  |---|---|---|---|
@@ -1966,6 +2025,43 @@ This operation does not require authentication
1966
2025
  This operation does not require authentication
1967
2026
  </aside>
1968
2027
 
2028
+ ## post__api_v1_account_setCurrentTenantId
2029
+
2030
+ `POST /api/v1/account/setCurrentTenantId`
2031
+
2032
+ > Body parameter
2033
+
2034
+ ```json
2035
+ {
2036
+ "type": "object",
2037
+ "required": [
2038
+ "tenantId"
2039
+ ],
2040
+ "properties": {
2041
+ "tenantId": {
2042
+ "type": "string"
2043
+ }
2044
+ }
2045
+ }
2046
+ ```
2047
+
2048
+ <h3 id="post__api_v1_account_setcurrenttenantid-parameters">Parameters</h3>
2049
+
2050
+ |Name|In|Type|Required|Description|
2051
+ |---|---|---|---|---|
2052
+ |body|body|object|true|none|
2053
+ |» tenantId|body|string|true|none|
2054
+
2055
+ <h3 id="post__api_v1_account_setcurrenttenantid-responses">Responses</h3>
2056
+
2057
+ |Status|Meaning|Description|Schema|
2058
+ |---|---|---|---|
2059
+ |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
2060
+
2061
+ <aside class="success">
2062
+ This operation does not require authentication
2063
+ </aside>
2064
+
1969
2065
  # Schemas
1970
2066
 
1971
2067
 
package/index.js CHANGED
@@ -2,6 +2,7 @@ const fp = require('fastify-plugin');
2
2
  const packageJson = require('./package.json');
3
3
  const path = require('path');
4
4
  const merge = require('lodash/merge');
5
+ const { Unauthorized } = require('http-errors');
5
6
 
6
7
  module.exports = fp(
7
8
  async function (fastify, options) {
@@ -9,6 +10,7 @@ module.exports = fp(
9
10
  options = merge(
10
11
  {
11
12
  prefix: `/api/v${packageJson.version.split('.')[0]}/account`, //如果为true,发送邮件和短信将不调用,验证码随response返回
13
+ dbTableNamePrefix: 't_account_',
12
14
  isTest: false,
13
15
  jwt: {
14
16
  secret: 'super-secret'
@@ -23,7 +25,12 @@ module.exports = fp(
23
25
  options,
24
26
  name: 'account',
25
27
  modules: [
26
- ['models', await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'))],
28
+ [
29
+ 'models',
30
+ await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
31
+ prefix: options.dbTableNamePrefix
32
+ })
33
+ ],
27
34
  ['services', path.resolve(__dirname, './libs/services')],
28
35
  ['controllers', path.resolve(__dirname, './libs/controllers')],
29
36
  [
@@ -34,13 +41,15 @@ module.exports = fp(
34
41
  //这里判断失效时间
35
42
  //info.iat
36
43
  request.authenticatePayload = info.payload;
37
- request.userInfo = await fastify.account.services.user.getUserInfo(request.authenticatePayload);
44
+ request.userInfo = await fastify.account.services.user.getUser(request.authenticatePayload);
38
45
  },
39
46
  tenant: async request => {
40
- request.tenantInfo = await fastify.account.services.tenant.tenantUserAuthenticate(request.userInfo);
47
+ request.tenantInfo = await fastify.account.services.tenantUser.getTenantUserByUserId(request.userInfo);
41
48
  },
42
49
  admin: async request => {
43
- request.adminInfo = await fastify.account.services.admin.superAdminAuthenticate(request.userInfo);
50
+ if (!(await fastify.account.services.admin.checkIsSuperAdmin(request.userInfo))) {
51
+ throw Unauthorized('不能执行该操作,需要超级管理员权限');
52
+ }
44
53
  }
45
54
  }
46
55
  ]
@@ -1,5 +1,6 @@
1
1
  const fp = require('fastify-plugin');
2
2
  module.exports = fp(async (fastify, options) => {
3
+ const { services } = fastify.account;
3
4
  fastify.post(
4
5
  `${options.prefix}/sendEmailCode`,
5
6
  {
@@ -18,14 +19,7 @@ module.exports = fp(async (fastify, options) => {
18
19
  schema: {
19
20
  type: 'object',
20
21
  properties: {
21
- code: { type: 'number' },
22
- data: {
23
- type: 'object',
24
- properties: {
25
- code: { type: 'string', description: '验证码' }
26
- }
27
- },
28
- msg: { type: 'string' }
22
+ code: { type: 'string', description: '验证码' }
29
23
  }
30
24
  }
31
25
  }
@@ -36,7 +30,7 @@ module.exports = fp(async (fastify, options) => {
36
30
  },
37
31
  async request => {
38
32
  const { email } = request.body;
39
- const code = await fastify.account.services.account.sendEmailCode({ email });
33
+ const code = await services.account.sendEmailCode({ email });
40
34
  return options.isTest ? { code } : {};
41
35
  }
42
36
  );
@@ -56,7 +50,7 @@ module.exports = fp(async (fastify, options) => {
56
50
  },
57
51
  async request => {
58
52
  const { phone } = request.body;
59
- const code = await fastify.account.services.account.sendSMSCode({ phone });
53
+ const code = await services.account.sendSMSCode({ phone });
60
54
  return options.isTest ? { code } : {};
61
55
  }
62
56
  );
@@ -78,7 +72,7 @@ module.exports = fp(async (fastify, options) => {
78
72
  },
79
73
  async request => {
80
74
  const { name, type, code } = request.body;
81
- const isPass = await fastify.account.services.account.verificationCodeValidate({
75
+ const isPass = await services.account.verificationCodeValidate({
82
76
  name,
83
77
  type,
84
78
  code
@@ -116,7 +110,7 @@ module.exports = fp(async (fastify, options) => {
116
110
  },
117
111
  async request => {
118
112
  const { phone, email } = request.body;
119
- return { isExists: await fastify.account.services.user.accountIsExists({ phone, email }) };
113
+ return { isExists: await services.user.accountIsExists({ phone, email }) };
120
114
  }
121
115
  );
122
116
 
@@ -162,7 +156,7 @@ module.exports = fp(async (fastify, options) => {
162
156
  },
163
157
  async request => {
164
158
  const account = request.body;
165
- return await fastify.account.services.account.register(account);
159
+ return await services.account.register(account);
166
160
  }
167
161
  );
168
162
 
@@ -182,8 +176,8 @@ module.exports = fp(async (fastify, options) => {
182
176
  },
183
177
  async request => {
184
178
  const { username, password } = request.body;
185
- const token = await fastify.account.services.account.login({ username, password, ip: request.ip });
186
- return { token };
179
+ const { token, user } = await services.account.login({ username, password, ip: request.ip });
180
+ return { token, currentTenantId: user.currentTenantId };
187
181
  }
188
182
  );
189
183
  });
@@ -1,14 +1,15 @@
1
1
  const fp = require('fastify-plugin');
2
2
 
3
3
  module.exports = fp(async (fastify, options) => {
4
+ const { authenticate, services } = fastify.account;
4
5
  // 用于系统初始化时,设置第一个用户,只能使用一次,其他用户由该用户创建
5
6
  fastify.post(
6
7
  `${options.prefix}/initSuperAdmin`,
7
8
  {
8
- onRequest: [fastify.account.authenticate.user]
9
+ onRequest: [authenticate.user]
9
10
  },
10
11
  async request => {
11
- await fastify.account.services.admin.initSuperAdmin(await fastify.account.services.user.getUserInfo(request.authenticatePayload));
12
+ await services.admin.initSuperAdmin(request.userInfo);
12
13
  return {};
13
14
  }
14
15
  );
@@ -16,24 +17,46 @@ module.exports = fp(async (fastify, options) => {
16
17
  fastify.get(
17
18
  `${options.prefix}/admin/getSuperAdminInfo`,
18
19
  {
19
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin]
20
+ onRequest: [authenticate.user, authenticate.admin]
20
21
  },
21
22
  async request => {
22
23
  return { userInfo: request.userInfo };
23
24
  }
24
25
  );
25
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
+
26
49
  fastify.post(
27
50
  `${options.prefix}/admin/addUser`,
28
51
  {
29
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
52
+ onRequest: [authenticate.user, authenticate.admin],
30
53
  schema: {
31
54
  body: {}
32
55
  }
33
56
  },
34
57
  async request => {
35
58
  const userInfo = request.body;
36
- await fastify.account.services.admin.addUser(Object.assign({}, userInfo, { password: options.defaultPassword }));
59
+ await services.admin.addUser(Object.assign({}, userInfo, { password: services.account.md5(options.defaultPassword) }));
37
60
  return {};
38
61
  }
39
62
  );
@@ -41,7 +64,7 @@ module.exports = fp(async (fastify, options) => {
41
64
  fastify.get(
42
65
  `${options.prefix}/admin/getAllUserList`,
43
66
  {
44
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
67
+ onRequest: [authenticate.user, authenticate.admin],
45
68
  schema: {
46
69
  query: {}
47
70
  }
@@ -54,7 +77,7 @@ module.exports = fp(async (fastify, options) => {
54
77
  },
55
78
  request.query
56
79
  );
57
- return await fastify.account.services.admin.getAllUserList({
80
+ return await services.user.getAllUserList({
58
81
  filter,
59
82
  perPage,
60
83
  currentPage
@@ -65,7 +88,7 @@ module.exports = fp(async (fastify, options) => {
65
88
  fastify.post(
66
89
  `${options.prefix}/admin/resetUserPassword`,
67
90
  {
68
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
91
+ onRequest: [authenticate.user, authenticate.admin],
69
92
  schema: {
70
93
  body: {
71
94
  type: 'object',
@@ -78,7 +101,7 @@ module.exports = fp(async (fastify, options) => {
78
101
  }
79
102
  },
80
103
  async request => {
81
- await fastify.account.services.admin.resetUserPassword(request.body);
104
+ await services.admin.resetUserPassword(request.body);
82
105
  return {};
83
106
  }
84
107
  );
@@ -86,7 +109,7 @@ module.exports = fp(async (fastify, options) => {
86
109
  fastify.post(
87
110
  `${options.prefix}/admin/saveUser`,
88
111
  {
89
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
112
+ onRequest: [authenticate.user, authenticate.admin],
90
113
  schema: {
91
114
  body: {
92
115
  type: 'object',
@@ -104,7 +127,7 @@ module.exports = fp(async (fastify, options) => {
104
127
  },
105
128
  async request => {
106
129
  const user = request.body;
107
- await fastify.account.services.user.saveUser(user);
130
+ await services.user.saveUser(user);
108
131
  return {};
109
132
  }
110
133
  );
@@ -112,7 +135,7 @@ module.exports = fp(async (fastify, options) => {
112
135
  fastify.post(
113
136
  `${options.prefix}/admin/closeUser`,
114
137
  {
115
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
138
+ onRequest: [authenticate.user, authenticate.admin],
116
139
  schema: {
117
140
  body: {
118
141
  type: 'object',
@@ -125,7 +148,7 @@ module.exports = fp(async (fastify, options) => {
125
148
  },
126
149
  async request => {
127
150
  const { id } = request.body;
128
- await fastify.account.services.user.closeUser({ id });
151
+ await services.user.closeUser({ id });
129
152
  return {};
130
153
  }
131
154
  );
@@ -133,7 +156,7 @@ module.exports = fp(async (fastify, options) => {
133
156
  fastify.post(
134
157
  `${options.prefix}/admin/openUser`,
135
158
  {
136
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
159
+ onRequest: [authenticate.user, authenticate.admin],
137
160
  schema: {
138
161
  body: {
139
162
  type: 'object',
@@ -146,7 +169,7 @@ module.exports = fp(async (fastify, options) => {
146
169
  },
147
170
  async request => {
148
171
  const { id } = request.body;
149
- await fastify.account.services.user.openUser({ id });
172
+ await services.user.openUser({ id });
150
173
  return {};
151
174
  }
152
175
  );
@@ -1,10 +1,11 @@
1
1
  const fp = require('fastify-plugin');
2
2
 
3
3
  module.exports = fp(async (fastify, options) => {
4
+ const { authenticate, services } = fastify.account;
4
5
  fastify.post(
5
6
  `${options.prefix}/admin/addApplication`,
6
7
  {
7
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
8
+ onRequest: [authenticate.user, authenticate.admin],
8
9
  schema: {
9
10
  body: {
10
11
  type: 'object',
@@ -20,7 +21,7 @@ module.exports = fp(async (fastify, options) => {
20
21
  }
21
22
  },
22
23
  async request => {
23
- await fastify.account.services.permission.addApplication(request.body);
24
+ await services.application.addApplication(request.body);
24
25
  return {};
25
26
  }
26
27
  );
@@ -28,7 +29,7 @@ module.exports = fp(async (fastify, options) => {
28
29
  fastify.post(
29
30
  `${options.prefix}/admin/saveApplication`,
30
31
  {
31
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
32
+ onRequest: [authenticate.user, authenticate.admin],
32
33
  schema: {
33
34
  body: {
34
35
  type: 'object',
@@ -45,7 +46,7 @@ module.exports = fp(async (fastify, options) => {
45
46
  }
46
47
  },
47
48
  async request => {
48
- await fastify.account.services.permission.saveApplication(request.body);
49
+ await services.application.saveApplication(request.body);
49
50
  return {};
50
51
  }
51
52
  );
@@ -53,7 +54,7 @@ module.exports = fp(async (fastify, options) => {
53
54
  fastify.post(
54
55
  `${options.prefix}/admin/deleteApplication`,
55
56
  {
56
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
57
+ onRequest: [authenticate.user, authenticate.admin],
57
58
  schema: {
58
59
  body: {
59
60
  type: 'object',
@@ -66,7 +67,7 @@ module.exports = fp(async (fastify, options) => {
66
67
  },
67
68
  async request => {
68
69
  const { id } = request.body;
69
- await fastify.account.services.permission.deleteApplication({ id });
70
+ await services.application.deleteApplication({ id });
70
71
  return {};
71
72
  }
72
73
  );
@@ -74,7 +75,7 @@ module.exports = fp(async (fastify, options) => {
74
75
  fastify.get(
75
76
  `${options.prefix}/admin/getApplicationList`,
76
77
  {
77
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
78
+ onRequest: [authenticate.user, authenticate.admin],
78
79
  schema: {
79
80
  query: {
80
81
  type: 'object',
@@ -86,14 +87,14 @@ module.exports = fp(async (fastify, options) => {
86
87
  },
87
88
  async request => {
88
89
  const { tenantId } = request.query;
89
- return await fastify.account.services.permission.getApplicationList({ tenantId });
90
+ return await services.application.getApplicationList({ tenantId });
90
91
  }
91
92
  );
92
93
 
93
94
  fastify.post(
94
95
  `${options.prefix}/admin/addPermission`,
95
96
  {
96
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
97
+ onRequest: [authenticate.user, authenticate.admin],
97
98
  schema: {
98
99
  body: {
99
100
  type: 'object',
@@ -112,7 +113,7 @@ module.exports = fp(async (fastify, options) => {
112
113
  }
113
114
  },
114
115
  async request => {
115
- await fastify.account.services.permission.addPermission(request.body);
116
+ await services.permission.addPermission(request.body);
116
117
  return {};
117
118
  }
118
119
  );
@@ -120,7 +121,7 @@ module.exports = fp(async (fastify, options) => {
120
121
  fastify.get(
121
122
  `${options.prefix}/admin/getPermissionList`,
122
123
  {
123
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
124
+ onRequest: [authenticate.user, authenticate.admin],
124
125
  schema: {
125
126
  query: {
126
127
  type: 'object',
@@ -134,14 +135,14 @@ module.exports = fp(async (fastify, options) => {
134
135
  },
135
136
  async request => {
136
137
  const { applicationId, tenantId } = request.query;
137
- return await fastify.account.services.permission.getPermissionList({ applicationId, tenantId });
138
+ return await services.permission.getPermissionList({ applicationId, tenantId });
138
139
  }
139
140
  );
140
141
 
141
142
  fastify.post(
142
143
  `${options.prefix}/admin/deletePermission`,
143
144
  {
144
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
145
+ onRequest: [authenticate.user, authenticate.admin],
145
146
  schema: {
146
147
  body: {
147
148
  type: 'object',
@@ -155,7 +156,7 @@ module.exports = fp(async (fastify, options) => {
155
156
  async request => {
156
157
  const { id } = request.body;
157
158
 
158
- await fastify.account.services.permission.deletePermission({ id });
159
+ await services.permission.deletePermission({ id });
159
160
 
160
161
  return {};
161
162
  }
@@ -164,7 +165,7 @@ module.exports = fp(async (fastify, options) => {
164
165
  fastify.post(
165
166
  `${options.prefix}/admin/savePermission`,
166
167
  {
167
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
168
+ onRequest: [authenticate.user, authenticate.admin],
168
169
  schema: {
169
170
  body: {
170
171
  type: 'object',
@@ -180,7 +181,7 @@ module.exports = fp(async (fastify, options) => {
180
181
  }
181
182
  },
182
183
  async request => {
183
- await fastify.account.services.permission.savePermission(request.body);
184
+ await services.permission.savePermission(request.body);
184
185
  return {};
185
186
  }
186
187
  );
@@ -188,24 +189,27 @@ module.exports = fp(async (fastify, options) => {
188
189
  fastify.post(
189
190
  `${options.prefix}/admin/saveTenantPermissionList`,
190
191
  {
191
- body: {
192
- type: 'object',
193
- required: ['tenantId', 'applications', 'permissions'],
194
- properties: {
195
- tenantId: { type: 'string' },
196
- applications: {
197
- type: 'array',
198
- items: { type: 'string' }
199
- },
200
- permissions: {
201
- type: 'array',
202
- items: { type: 'number' }
192
+ onRequest: [authenticate.user, authenticate.admin],
193
+ schema: {
194
+ body: {
195
+ type: 'object',
196
+ required: ['tenantId', 'applications', 'permissions'],
197
+ properties: {
198
+ tenantId: { type: 'string' },
199
+ applications: {
200
+ type: 'array',
201
+ items: { type: 'string' }
202
+ },
203
+ permissions: {
204
+ type: 'array',
205
+ items: { type: 'number' }
206
+ }
203
207
  }
204
208
  }
205
209
  }
206
210
  },
207
211
  async request => {
208
- await fastify.account.services.permission.saveTenantPermissionList(request.body);
212
+ await services.permission.saveTenantPermissionList(request.body);
209
213
 
210
214
  return {};
211
215
  }
@@ -214,17 +218,20 @@ module.exports = fp(async (fastify, options) => {
214
218
  fastify.get(
215
219
  `${options.prefix}/admin/getTenantPermissionList`,
216
220
  {
217
- query: {
218
- type: 'object',
219
- required: ['tenantId'],
220
- properties: {
221
- tenantId: { type: 'string' }
221
+ onRequest: [authenticate.user, authenticate.admin],
222
+ schema: {
223
+ query: {
224
+ type: 'object',
225
+ required: ['tenantId'],
226
+ properties: {
227
+ tenantId: { type: 'string' }
228
+ }
222
229
  }
223
230
  }
224
231
  },
225
232
  async request => {
226
233
  const { tenantId } = request.query;
227
- return await fastify.account.services.permission.getTenantPermissionList({ tenantId });
234
+ return await services.permission.getTenantPermissionList({ tenantId });
228
235
  }
229
236
  );
230
237
  });