@kne/fastify-account 1.0.0-alpha.2 → 1.0.0-alpha.4

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 +47 -2
  2. package/index.js +10 -4
  3. package/libs/controllers/account.js +7 -6
  4. package/libs/controllers/admin.js +16 -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 +7 -6
  9. package/libs/controllers/user.js +4 -3
  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 +13 -13
  18. package/libs/models/tenant-role-permission.js +9 -14
  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 +26 -16
  33. package/libs/services/admin.js +14 -116
  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 +84 -0
  38. package/libs/services/tenant-role.js +108 -0
  39. package/libs/services/tenant-user.js +486 -0
  40. package/libs/services/tenant.js +68 -669
  41. package/libs/services/user.js +63 -33
  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.1"
25
+ title: "@kne/fastify-account v1.0.0-alpha.3"
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.1</h1>
45
+ <h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.3</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|
package/index.js CHANGED
@@ -9,6 +9,7 @@ module.exports = fp(
9
9
  options = merge(
10
10
  {
11
11
  prefix: `/api/v${packageJson.version.split('.')[0]}/account`, //如果为true,发送邮件和短信将不调用,验证码随response返回
12
+ dbTableNamePrefix: 't_account_',
12
13
  isTest: false,
13
14
  jwt: {
14
15
  secret: 'super-secret'
@@ -23,7 +24,12 @@ module.exports = fp(
23
24
  options,
24
25
  name: 'account',
25
26
  modules: [
26
- ['models', await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'))],
27
+ [
28
+ 'models',
29
+ await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
30
+ prefix: options.dbTableNamePrefix
31
+ })
32
+ ],
27
33
  ['services', path.resolve(__dirname, './libs/services')],
28
34
  ['controllers', path.resolve(__dirname, './libs/controllers')],
29
35
  [
@@ -34,13 +40,13 @@ module.exports = fp(
34
40
  //这里判断失效时间
35
41
  //info.iat
36
42
  request.authenticatePayload = info.payload;
37
- request.userInfo = await fastify.account.services.user.getUserInfo(request.authenticatePayload);
43
+ request.userInfo = await fastify.account.services.user.getUser(request.authenticatePayload);
38
44
  },
39
45
  tenant: async request => {
40
- request.tenantInfo = await fastify.account.services.tenant.tenantUserAuthenticate(request.userInfo);
46
+ request.tenantInfo = await fastify.account.services.tenantUser.getTenantUserByUserId(request.userInfo);
41
47
  },
42
48
  admin: async request => {
43
- request.adminInfo = await fastify.account.services.admin.superAdminAuthenticate(request.userInfo);
49
+ request.adminInfo = await fastify.account.services.admin.checkSuperAdmin(request.userInfo);
44
50
  }
45
51
  }
46
52
  ]
@@ -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
  {
@@ -36,7 +37,7 @@ module.exports = fp(async (fastify, options) => {
36
37
  },
37
38
  async request => {
38
39
  const { email } = request.body;
39
- const code = await fastify.account.services.account.sendEmailCode({ email });
40
+ const code = await services.account.sendEmailCode({ email });
40
41
  return options.isTest ? { code } : {};
41
42
  }
42
43
  );
@@ -56,7 +57,7 @@ module.exports = fp(async (fastify, options) => {
56
57
  },
57
58
  async request => {
58
59
  const { phone } = request.body;
59
- const code = await fastify.account.services.account.sendSMSCode({ phone });
60
+ const code = await services.account.sendSMSCode({ phone });
60
61
  return options.isTest ? { code } : {};
61
62
  }
62
63
  );
@@ -78,7 +79,7 @@ module.exports = fp(async (fastify, options) => {
78
79
  },
79
80
  async request => {
80
81
  const { name, type, code } = request.body;
81
- const isPass = await fastify.account.services.account.verificationCodeValidate({
82
+ const isPass = await services.account.verificationCodeValidate({
82
83
  name,
83
84
  type,
84
85
  code
@@ -116,7 +117,7 @@ module.exports = fp(async (fastify, options) => {
116
117
  },
117
118
  async request => {
118
119
  const { phone, email } = request.body;
119
- return { isExists: await fastify.account.services.user.accountIsExists({ phone, email }) };
120
+ return { isExists: await services.user.accountIsExists({ phone, email }) };
120
121
  }
121
122
  );
122
123
 
@@ -162,7 +163,7 @@ module.exports = fp(async (fastify, options) => {
162
163
  },
163
164
  async request => {
164
165
  const account = request.body;
165
- return await fastify.account.services.account.register(account);
166
+ return await services.account.register(account);
166
167
  }
167
168
  );
168
169
 
@@ -182,7 +183,7 @@ module.exports = fp(async (fastify, options) => {
182
183
  },
183
184
  async request => {
184
185
  const { username, password } = request.body;
185
- const { token, user } = await fastify.account.services.account.login({ username, password, ip: request.ip });
186
+ const { token, user } = await services.account.login({ username, password, ip: request.ip });
186
187
  return { token, currentTenantId: user.currentTenantId };
187
188
  }
188
189
  );
@@ -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(await services.user.getUser(request.authenticatePayload));
12
13
  return {};
13
14
  }
14
15
  );
@@ -16,7 +17,7 @@ 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 };
@@ -26,14 +27,14 @@ module.exports = fp(async (fastify, options) => {
26
27
  fastify.post(
27
28
  `${options.prefix}/admin/addUser`,
28
29
  {
29
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
30
+ onRequest: [authenticate.user, authenticate.admin],
30
31
  schema: {
31
32
  body: {}
32
33
  }
33
34
  },
34
35
  async request => {
35
36
  const userInfo = request.body;
36
- await fastify.account.services.admin.addUser(Object.assign({}, userInfo, { password: options.defaultPassword }));
37
+ await services.admin.addUser(Object.assign({}, userInfo, { password: options.defaultPassword }));
37
38
  return {};
38
39
  }
39
40
  );
@@ -41,7 +42,7 @@ module.exports = fp(async (fastify, options) => {
41
42
  fastify.get(
42
43
  `${options.prefix}/admin/getAllUserList`,
43
44
  {
44
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
45
+ onRequest: [authenticate.user, authenticate.admin],
45
46
  schema: {
46
47
  query: {}
47
48
  }
@@ -54,7 +55,7 @@ module.exports = fp(async (fastify, options) => {
54
55
  },
55
56
  request.query
56
57
  );
57
- return await fastify.account.services.admin.getAllUserList({
58
+ return await services.user.getAllUserList({
58
59
  filter,
59
60
  perPage,
60
61
  currentPage
@@ -65,7 +66,7 @@ module.exports = fp(async (fastify, options) => {
65
66
  fastify.post(
66
67
  `${options.prefix}/admin/resetUserPassword`,
67
68
  {
68
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
69
+ onRequest: [authenticate.user, authenticate.admin],
69
70
  schema: {
70
71
  body: {
71
72
  type: 'object',
@@ -78,7 +79,7 @@ module.exports = fp(async (fastify, options) => {
78
79
  }
79
80
  },
80
81
  async request => {
81
- await fastify.account.services.admin.resetUserPassword(request.body);
82
+ await services.admin.resetUserPassword(request.body);
82
83
  return {};
83
84
  }
84
85
  );
@@ -86,7 +87,7 @@ module.exports = fp(async (fastify, options) => {
86
87
  fastify.post(
87
88
  `${options.prefix}/admin/saveUser`,
88
89
  {
89
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
90
+ onRequest: [authenticate.user, authenticate.admin],
90
91
  schema: {
91
92
  body: {
92
93
  type: 'object',
@@ -104,7 +105,7 @@ module.exports = fp(async (fastify, options) => {
104
105
  },
105
106
  async request => {
106
107
  const user = request.body;
107
- await fastify.account.services.user.saveUser(user);
108
+ await services.user.saveUser(user);
108
109
  return {};
109
110
  }
110
111
  );
@@ -112,7 +113,7 @@ module.exports = fp(async (fastify, options) => {
112
113
  fastify.post(
113
114
  `${options.prefix}/admin/closeUser`,
114
115
  {
115
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
116
+ onRequest: [authenticate.user, authenticate.admin],
116
117
  schema: {
117
118
  body: {
118
119
  type: 'object',
@@ -125,7 +126,7 @@ module.exports = fp(async (fastify, options) => {
125
126
  },
126
127
  async request => {
127
128
  const { id } = request.body;
128
- await fastify.account.services.user.closeUser({ id });
129
+ await services.user.closeUser({ id });
129
130
  return {};
130
131
  }
131
132
  );
@@ -133,7 +134,7 @@ module.exports = fp(async (fastify, options) => {
133
134
  fastify.post(
134
135
  `${options.prefix}/admin/openUser`,
135
136
  {
136
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
137
+ onRequest: [authenticate.user, authenticate.admin],
137
138
  schema: {
138
139
  body: {
139
140
  type: 'object',
@@ -146,7 +147,7 @@ module.exports = fp(async (fastify, options) => {
146
147
  },
147
148
  async request => {
148
149
  const { id } = request.body;
149
- await fastify.account.services.user.openUser({ id });
150
+ await services.user.openUser({ id });
150
151
  return {};
151
152
  }
152
153
  );
@@ -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
  });
@@ -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.get(
5
6
  `${options.prefix}/admin/getRoleList`,
6
7
  {
7
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
8
+ onRequest: [authenticate.user, authenticate.admin],
8
9
  schema: {
9
10
  query: {
10
11
  type: 'object',
@@ -30,14 +31,14 @@ module.exports = fp(async (fastify, options) => {
30
31
  },
31
32
  request.query
32
33
  );
33
- return await fastify.account.services.tenant.getRoleList({ tenantId, perPage, currentPage, filter });
34
+ return await services.tenantRole.getTenantRoleList({ tenantId, perPage, currentPage, filter });
34
35
  }
35
36
  );
36
37
 
37
38
  fastify.post(
38
39
  `${options.prefix}/admin/addRole`,
39
40
  {
40
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
41
+ onRequest: [authenticate.user, authenticate.admin],
41
42
  schema: {
42
43
  body: {
43
44
  type: 'object',
@@ -52,7 +53,7 @@ module.exports = fp(async (fastify, options) => {
52
53
  },
53
54
  async request => {
54
55
  const { tenantId, name, description } = request.body;
55
- await fastify.account.services.tenant.addRole({ tenantId, name, description });
56
+ await services.tenantRole.addTenantRole({ tenantId, name, description });
56
57
 
57
58
  return {};
58
59
  }
@@ -61,7 +62,7 @@ module.exports = fp(async (fastify, options) => {
61
62
  fastify.post(
62
63
  `${options.prefix}/admin/saveRole`,
63
64
  {
64
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
65
+ onRequest: [authenticate.user, authenticate.admin],
65
66
  schema: {
66
67
  body: {
67
68
  type: 'object',
@@ -75,7 +76,7 @@ module.exports = fp(async (fastify, options) => {
75
76
  }
76
77
  },
77
78
  async request => {
78
- await fastify.account.services.tenant.saveRole(request.body);
79
+ await services.tenantRole.saveTenantRole(request.body);
79
80
  return {};
80
81
  }
81
82
  );
@@ -83,7 +84,7 @@ module.exports = fp(async (fastify, options) => {
83
84
  fastify.post(
84
85
  `${options.prefix}/admin/removeRole`,
85
86
  {
86
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
87
+ onRequest: [authenticate.user, authenticate.admin],
87
88
  schema: {
88
89
  body: {
89
90
  type: 'object',
@@ -96,7 +97,7 @@ module.exports = fp(async (fastify, options) => {
96
97
  },
97
98
  async request => {
98
99
  const { id } = request.body;
99
- await fastify.account.services.tenant.removeRole({ id });
100
+ await services.tenantRole.removeTenantRole({ id });
100
101
  return {};
101
102
  }
102
103
  );
@@ -104,7 +105,7 @@ module.exports = fp(async (fastify, options) => {
104
105
  fastify.get(
105
106
  `${options.prefix}/admin/getRolePermissionList`,
106
107
  {
107
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
108
+ onRequest: [authenticate.user, authenticate.admin],
108
109
  schema: {
109
110
  query: {
110
111
  type: 'object',
@@ -117,14 +118,14 @@ module.exports = fp(async (fastify, options) => {
117
118
  },
118
119
  async request => {
119
120
  const { id } = request.query;
120
- return await fastify.account.services.permission.getRolePermissionList({ roleId: id });
121
+ return await services.permission.getRolePermissionList({ roleId: id });
121
122
  }
122
123
  );
123
124
 
124
125
  fastify.post(
125
126
  `${options.prefix}/admin/saveRolePermissionList`,
126
127
  {
127
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
128
+ onRequest: [authenticate.user, authenticate.admin],
128
129
  schema: {
129
130
  roleId: { type: 'string' },
130
131
  applications: {
@@ -138,7 +139,7 @@ module.exports = fp(async (fastify, options) => {
138
139
  }
139
140
  },
140
141
  async request => {
141
- await fastify.account.services.permission.saveRolePermissionList(request.body);
142
+ await services.permission.saveRolePermissionList(request.body);
142
143
  return {};
143
144
  }
144
145
  );