@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
@@ -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/getAllTenantList`,
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',
@@ -38,7 +39,7 @@ module.exports = fp(async (fastify, options) => {
38
39
  },
39
40
  request.query
40
41
  );
41
- return await fastify.account.services.admin.getAllTenantList({
42
+ return await services.tenant.getAllTenantList({
42
43
  filter: { name },
43
44
  perPage,
44
45
  currentPage
@@ -49,7 +50,7 @@ module.exports = fp(async (fastify, options) => {
49
50
  fastify.get(
50
51
  `${options.prefix}/admin/getTenantInfo`,
51
52
  {
52
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
53
+ onRequest: [authenticate.user, authenticate.admin],
53
54
  schema: {
54
55
  query: {
55
56
  type: 'object',
@@ -61,14 +62,14 @@ module.exports = fp(async (fastify, options) => {
61
62
  },
62
63
  async request => {
63
64
  const { id } = request.query;
64
- return await fastify.account.services.tenant.getTenantInfo({ id });
65
+ return await services.tenant.getTenant({ id });
65
66
  }
66
67
  );
67
68
 
68
69
  fastify.post(
69
70
  `${options.prefix}/admin/addTenant`,
70
71
  {
71
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
72
+ onRequest: [authenticate.user, authenticate.admin],
72
73
  schema: {
73
74
  body: {
74
75
  type: 'object',
@@ -89,7 +90,7 @@ module.exports = fp(async (fastify, options) => {
89
90
  }
90
91
  },
91
92
  async request => {
92
- await fastify.account.services.admin.addTenant(request.body);
93
+ await services.tenant.addTenant(request.body);
93
94
  return {};
94
95
  }
95
96
  );
@@ -97,7 +98,7 @@ module.exports = fp(async (fastify, options) => {
97
98
  fastify.post(
98
99
  `${options.prefix}/admin/saveTenant`,
99
100
  {
100
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
101
+ onRequest: [authenticate.user, authenticate.admin],
101
102
  schema: {
102
103
  body: {
103
104
  type: 'object',
@@ -119,7 +120,7 @@ module.exports = fp(async (fastify, options) => {
119
120
  }
120
121
  },
121
122
  async request => {
122
- await fastify.account.services.admin.saveTenant(request.body);
123
+ await services.tenant.saveTenant(request.body);
123
124
  return {};
124
125
  }
125
126
  );
@@ -127,7 +128,7 @@ module.exports = fp(async (fastify, options) => {
127
128
  fastify.post(
128
129
  `${options.prefix}/admin/tenant/addOrg`,
129
130
  {
130
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
131
+ onRequest: [authenticate.user, authenticate.admin],
131
132
  required: ['name', 'tenantId', 'pid'],
132
133
  properties: {
133
134
  name: { type: 'string' },
@@ -136,14 +137,14 @@ module.exports = fp(async (fastify, options) => {
136
137
  }
137
138
  },
138
139
  async request => {
139
- return await fastify.account.services.tenant.addTenantOrg(request.body);
140
+ return await services.tenantOrg.addTenantOrg(request.body);
140
141
  }
141
142
  );
142
143
 
143
144
  fastify.get(
144
145
  `${options.prefix}/admin/tenant/orgList`,
145
146
  {
146
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
147
+ onRequest: [authenticate.user, authenticate.admin],
147
148
  schema: {
148
149
  query: {
149
150
  type: 'object',
@@ -155,14 +156,14 @@ module.exports = fp(async (fastify, options) => {
155
156
  },
156
157
  async request => {
157
158
  const { tenantId } = request.query;
158
- return await fastify.account.services.tenant.getTenantOrgList({ tenantId });
159
+ return await services.tenantOrg.getTenantOrgList({ tenantId });
159
160
  }
160
161
  );
161
162
 
162
163
  fastify.post(
163
164
  `${options.prefix}/admin/tenant/editOrg`,
164
165
  {
165
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
166
+ onRequest: [authenticate.user, authenticate.admin],
166
167
  required: ['name', 'tenantId', 'pid'],
167
168
  properties: {
168
169
  name: { type: 'string' },
@@ -171,7 +172,7 @@ module.exports = fp(async (fastify, options) => {
171
172
  }
172
173
  },
173
174
  async request => {
174
- await fastify.account.services.tenant.saveTenantOrg(request.body);
175
+ await services.tenantOrg.saveTenantOrg(request.body);
175
176
  return {};
176
177
  }
177
178
  );
@@ -179,7 +180,7 @@ module.exports = fp(async (fastify, options) => {
179
180
  fastify.post(
180
181
  `${options.prefix}/admin/tenant/removeOrg`,
181
182
  {
182
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
183
+ onRequest: [authenticate.user, authenticate.admin],
183
184
  required: ['tenantId', 'id'],
184
185
  properties: {
185
186
  tenantId: { type: 'string' },
@@ -187,7 +188,7 @@ module.exports = fp(async (fastify, options) => {
187
188
  }
188
189
  },
189
190
  async request => {
190
- await fastify.account.services.tenant.deleteTenantOrg(request.body);
191
+ await services.tenantOrg.deleteTenantOrg(request.body);
191
192
  return {};
192
193
  }
193
194
  );
@@ -195,7 +196,7 @@ module.exports = fp(async (fastify, options) => {
195
196
  fastify.get(
196
197
  `${options.prefix}/admin/getTenantUserList`,
197
198
  {
198
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
199
+ onRequest: [authenticate.user, authenticate.admin],
199
200
  schema: {
200
201
  query: {
201
202
  type: 'object',
@@ -207,13 +208,14 @@ module.exports = fp(async (fastify, options) => {
207
208
  },
208
209
  async request => {
209
210
  const { tenantId } = request.query;
210
- return await fastify.account.services.tenant.getTenantUserList({ tenantId });
211
+ return await services.tenantUser.getTenantUserList({ tenantId });
211
212
  }
212
213
  );
213
214
 
214
215
  fastify.post(
215
216
  `${options.prefix}/admin/addTenantUser`,
216
217
  {
218
+ onRequest: [authenticate.user, authenticate.admin],
217
219
  schema: {
218
220
  body: {
219
221
  type: 'object',
@@ -237,7 +239,7 @@ module.exports = fp(async (fastify, options) => {
237
239
  }
238
240
  },
239
241
  async request => {
240
- await fastify.account.services.tenant.addTenantUser(request.body);
242
+ await services.tenantUser.addTenantUser(request.body);
241
243
  return {};
242
244
  }
243
245
  );
@@ -245,6 +247,7 @@ module.exports = fp(async (fastify, options) => {
245
247
  fastify.post(
246
248
  `${options.prefix}/admin/saveTenantUser`,
247
249
  {
250
+ onRequest: [authenticate.user, authenticate.admin],
248
251
  schema: {
249
252
  body: {
250
253
  type: 'object',
@@ -267,7 +270,7 @@ module.exports = fp(async (fastify, options) => {
267
270
  }
268
271
  },
269
272
  async request => {
270
- await fastify.account.services.tenant.saveTenantUser(request.body);
273
+ await services.tenantUser.saveTenantUser(request.body);
271
274
  return {};
272
275
  }
273
276
  );
@@ -275,7 +278,7 @@ module.exports = fp(async (fastify, options) => {
275
278
  fastify.post(
276
279
  `${options.prefix}/admin/deleteTenantUser`,
277
280
  {
278
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
281
+ onRequest: [authenticate.user, authenticate.admin],
279
282
  schema: {
280
283
  body: {
281
284
  type: 'object',
@@ -289,7 +292,7 @@ module.exports = fp(async (fastify, options) => {
289
292
  },
290
293
  async request => {
291
294
  const { tenantId, tenantUserId } = request.body;
292
- await fastify.account.services.tenant.deleteTenantUser({ tenantId, tenantUserId });
295
+ await services.tenantUser.deleteTenantUser({ tenantId, tenantUserId });
293
296
  return {};
294
297
  }
295
298
  );
@@ -297,7 +300,7 @@ module.exports = fp(async (fastify, options) => {
297
300
  fastify.post(
298
301
  `${options.prefix}/admin/closeTenant`,
299
302
  {
300
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
303
+ onRequest: [authenticate.user, authenticate.admin],
301
304
  schema: {
302
305
  body: {
303
306
  type: 'object',
@@ -310,7 +313,7 @@ module.exports = fp(async (fastify, options) => {
310
313
  },
311
314
  async request => {
312
315
  const { tenantId } = request.body;
313
- await fastify.account.services.tenant.closeTenant({ tenantId });
316
+ await services.tenant.closeTenant({ tenantId });
314
317
  return {};
315
318
  }
316
319
  );
@@ -318,7 +321,7 @@ module.exports = fp(async (fastify, options) => {
318
321
  fastify.post(
319
322
  `${options.prefix}/admin/openTenant`,
320
323
  {
321
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
324
+ onRequest: [authenticate.user, authenticate.admin],
322
325
  schema: {
323
326
  body: {
324
327
  type: 'object',
@@ -331,7 +334,7 @@ module.exports = fp(async (fastify, options) => {
331
334
  },
332
335
  async request => {
333
336
  const { tenantId } = request.body;
334
- await fastify.account.services.tenant.openTenant({ tenantId });
337
+ await services.tenant.openTenant({ tenantId });
335
338
  return {};
336
339
  }
337
340
  );
@@ -339,7 +342,7 @@ module.exports = fp(async (fastify, options) => {
339
342
  fastify.post(
340
343
  `${options.prefix}/admin/closeTenantUser`,
341
344
  {
342
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
345
+ onRequest: [authenticate.user, authenticate.admin],
343
346
  schema: {
344
347
  body: {
345
348
  type: 'object',
@@ -353,7 +356,7 @@ module.exports = fp(async (fastify, options) => {
353
356
  },
354
357
  async request => {
355
358
  const { tenantId, tenantUserId } = request.body;
356
- await fastify.account.services.tenant.closeTenantUser({ tenantId, tenantUserId });
359
+ await services.tenantUser.closeTenantUser({ tenantId, tenantUserId });
357
360
  return {};
358
361
  }
359
362
  );
@@ -361,7 +364,7 @@ module.exports = fp(async (fastify, options) => {
361
364
  fastify.post(
362
365
  `${options.prefix}/admin/openTenantUser`,
363
366
  {
364
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
367
+ onRequest: [authenticate.user, authenticate.admin],
365
368
  schema: {
366
369
  body: {
367
370
  type: 'object',
@@ -375,7 +378,7 @@ module.exports = fp(async (fastify, options) => {
375
378
  },
376
379
  async request => {
377
380
  const { tenantId, tenantUserId } = request.body;
378
- await fastify.account.services.tenant.openTenantUser({ tenantId, tenantUserId });
381
+ await services.tenantUser.openTenantUser({ tenantId, tenantUserId });
379
382
  return {};
380
383
  }
381
384
  );
@@ -383,7 +386,7 @@ module.exports = fp(async (fastify, options) => {
383
386
  fastify.get(
384
387
  `${options.prefix}/admin/getInviteList`,
385
388
  {
386
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
389
+ onRequest: [authenticate.user, authenticate.admin],
387
390
  schema: {
388
391
  query: {
389
392
  type: 'object',
@@ -403,14 +406,14 @@ module.exports = fp(async (fastify, options) => {
403
406
  request.query
404
407
  );
405
408
 
406
- return await fastify.account.services.tenant.getInviteList({ filter, perPage, currentPage, tenantId });
409
+ return await services.tenantInvite.getInviteList({ filter, perPage, currentPage, tenantId });
407
410
  }
408
411
  );
409
412
 
410
413
  fastify.post(
411
414
  `${options.prefix}/admin/addInviteToken`,
412
415
  {
413
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
416
+ onRequest: [authenticate.user, authenticate.admin],
414
417
  schema: {
415
418
  body: {
416
419
  type: 'object',
@@ -434,7 +437,7 @@ module.exports = fp(async (fastify, options) => {
434
437
  },
435
438
  async request => {
436
439
  const { tenantId, info } = request.body;
437
- await fastify.account.services.tenant.addInviteToken({ tenantId, info });
440
+ await services.tenantInvite.addInviteToken({ tenantId, info });
438
441
  return {};
439
442
  }
440
443
  );
@@ -442,7 +445,7 @@ module.exports = fp(async (fastify, options) => {
442
445
  fastify.post(
443
446
  `${options.prefix}/admin/deleteInviteToken`,
444
447
  {
445
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.admin],
448
+ onRequest: [authenticate.user, authenticate.admin],
446
449
  schema: {
447
450
  body: {
448
451
  type: 'object',
@@ -454,7 +457,7 @@ module.exports = fp(async (fastify, options) => {
454
457
  }
455
458
  },
456
459
  async request => {
457
- await fastify.account.services.tenant.deleteInviteToken({ id: request.body.id });
460
+ await services.tenantInvite.deleteInviteToken({ id: request.body.id });
458
461
  return {};
459
462
  }
460
463
  );
@@ -1,19 +1,20 @@
1
1
  const fp = require('fastify-plugin');
2
2
  module.exports = fp(async (fastify, options) => {
3
+ const { authenticate, services } = fastify.account;
3
4
  fastify.get(
4
5
  `${options.prefix}/tenant/getUserTenant`,
5
6
  {
6
- onRequest: [fastify.account.authenticate.user]
7
+ onRequest: [authenticate.user]
7
8
  },
8
9
  async request => {
9
- return await fastify.account.services.tenant.getUserTenant(request.authenticatePayload);
10
+ return await services.tenantUser.getUserTenant(request.authenticatePayload);
10
11
  }
11
12
  );
12
13
 
13
14
  fastify.get(
14
15
  `${options.prefix}/tenant/getTenantUserInfo`,
15
16
  {
16
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.tenant]
17
+ onRequest: [authenticate.user, authenticate.tenant]
17
18
  },
18
19
  async request => {
19
20
  return request.tenantInfo;
@@ -23,11 +24,11 @@ module.exports = fp(async (fastify, options) => {
23
24
  fastify.get(
24
25
  `${options.prefix}/tenant/orgList`,
25
26
  {
26
- onRequest: [fastify.account.authenticate.user, fastify.account.authenticate.tenant]
27
+ onRequest: [authenticate.user, authenticate.tenant]
27
28
  },
28
29
  async request => {
29
- const { tenantId } = request.tenantInfo;
30
- return await fastify.account.services.tenant.getTenantOrgList({ tenantId });
30
+ const { id: tenantId } = request.tenantInfo.tenant;
31
+ return await services.tenantOrg.getTenantOrgList({ tenantId });
31
32
  }
32
33
  );
33
34
  });
@@ -1,9 +1,10 @@
1
1
  const fp = require('fastify-plugin');
2
2
  module.exports = fp(async (fastify, options) => {
3
+ const { authenticate, services } = fastify.account;
3
4
  fastify.get(
4
5
  `${options.prefix}/getUserInfo`,
5
6
  {
6
- onRequest: [fastify.account.authenticate.user]
7
+ onRequest: [authenticate.user]
7
8
  },
8
9
  async request => {
9
10
  return { userInfo: request.userInfo };
@@ -13,7 +14,7 @@ module.exports = fp(async (fastify, options) => {
13
14
  fastify.post(
14
15
  `${options.prefix}/setCurrentTenantId`,
15
16
  {
16
- onRequest: [fastify.account.authenticate.user],
17
+ onRequest: [authenticate.user],
17
18
  schema: {
18
19
  body: {
19
20
  type: 'object',
@@ -26,7 +27,7 @@ module.exports = fp(async (fastify, options) => {
26
27
  },
27
28
  async request => {
28
29
  const { tenantId } = request.body;
29
- await fastify.account.services.user.setCurrentTenantId({ id: request.userInfo.id, tenantId });
30
+ await services.user.setCurrentTenantId({ id: request.userInfo.id, tenantId });
30
31
  return {};
31
32
  }
32
33
  );
@@ -1,7 +1,6 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'adminRole',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  userId: {
6
5
  type: DataTypes.UUID,
7
6
  allowNull: false
@@ -11,9 +10,6 @@ module.exports = (sequelize, DataTypes) => {
11
10
  allowNull: false
12
11
  },
13
12
  target: DataTypes.STRING
14
- },
15
- {
16
- paranoid: true
17
13
  }
18
- );
14
+ };
19
15
  };
@@ -1,12 +1,15 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'application',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
5
+ type: DataTypes.INTEGER,
6
+ autoIncrement: true,
8
7
  primaryKey: true
9
8
  },
9
+ uuid: {
10
+ type: DataTypes.UUID,
11
+ defaultValue: DataTypes.UUIDV4
12
+ },
10
13
  avatar: DataTypes.STRING,
11
14
  name: {
12
15
  type: DataTypes.STRING,
@@ -23,14 +26,17 @@ module.exports = (sequelize, DataTypes) => {
23
26
  defaultValue: 0
24
27
  }
25
28
  },
26
- {
27
- paranoid: true,
29
+ options: {
28
30
  indexes: [
29
31
  {
30
32
  unique: true,
31
- fields: ['code', 'deletedAt']
33
+ fields: ['code', 'deleted_at']
34
+ },
35
+ {
36
+ unique: true,
37
+ fields: ['uuid', 'deleted_at']
32
38
  }
33
39
  ]
34
40
  }
35
- );
41
+ };
36
42
  };
@@ -1,15 +1,11 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'loginLog',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  userId: {
6
5
  type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  ip: DataTypes.STRING
10
- },
11
- {
12
- paranoid: true
13
9
  }
14
- );
10
+ };
15
11
  };
@@ -1,9 +1,8 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'permission',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  applicationId: {
6
- type: DataTypes.STRING,
5
+ type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  code: {
@@ -40,14 +39,13 @@ module.exports = (sequelize, DataTypes) => {
40
39
  defaultValue: 0
41
40
  }
42
41
  },
43
- {
44
- paranoid: true,
42
+ options: {
45
43
  indexes: [
46
44
  {
47
45
  unique: true,
48
- fields: ['code', 'applicationId', 'pid', 'deletedAt']
46
+ fields: ['code', 'application_id', 'pid', 'deleted_at']
49
47
  }
50
48
  ]
51
49
  }
52
- );
50
+ };
53
51
  };
@@ -1,13 +1,12 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'tenantApplication',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  tenantId: {
6
- type: DataTypes.STRING,
5
+ type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  applicationId: {
10
- type: DataTypes.INTEGER,
9
+ type: DataTypes.UUID,
11
10
  allowNull: false
12
11
  },
13
12
  status: {
@@ -15,14 +14,13 @@ module.exports = (sequelize, DataTypes) => {
15
14
  defaultValue: 0 //0:开启 11:关闭
16
15
  }
17
16
  },
18
- {
19
- paranoid: true,
17
+ options: {
20
18
  indexes: [
21
19
  {
22
20
  unique: true,
23
- fields: ['tenantId', 'applicationId', 'deletedAt']
21
+ fields: ['tenant_id', 'application_id', 'deleted_at']
24
22
  }
25
23
  ]
26
24
  }
27
- );
25
+ };
28
26
  };
@@ -1,9 +1,8 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'tenantOrg',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  tenantId: {
6
- type: DataTypes.STRING,
5
+ type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  name: {
@@ -22,9 +21,6 @@ module.exports = (sequelize, DataTypes) => {
22
21
  type: DataTypes.INTEGER,
23
22
  defaultValue: 0
24
23
  }
25
- },
26
- {
27
- paranoid: true
28
24
  }
29
- );
25
+ };
30
26
  };
@@ -1,9 +1,8 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- return sequelize.define(
3
- 'tenantPermission',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  tenantId: {
6
- type: DataTypes.STRING,
5
+ type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  permissionId: {
@@ -15,14 +14,13 @@ module.exports = (sequelize, DataTypes) => {
15
14
  defaultValue: 0 //0:开启 11:关闭
16
15
  }
17
16
  },
18
- {
19
- paranoid: true,
17
+ options: {
20
18
  indexes: [
21
19
  {
22
20
  unique: true,
23
- fields: ['tenantId', 'permissionId', 'deletedAt']
21
+ fields: ['tenant_id', 'permission_id', 'deleted_at']
24
22
  }
25
23
  ]
26
24
  }
27
- );
25
+ };
28
26
  };
@@ -1,13 +1,12 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const tenantRoleApplication = sequelize.define(
3
- 'tenantRoleApplication',
4
- {
1
+ module.exports = ({ DataTypes }) => {
2
+ return {
3
+ model: {
5
4
  tenantId: {
6
- type: DataTypes.STRING,
5
+ type: DataTypes.UUID,
7
6
  allowNull: false
8
7
  },
9
8
  applicationId: {
10
- type: DataTypes.INTEGER,
9
+ type: DataTypes.UUID,
11
10
  allowNull: false
12
11
  },
13
12
  roleId: {
@@ -19,19 +18,20 @@ module.exports = (sequelize, DataTypes) => {
19
18
  defaultValue: 0 //0:开启 11:关闭
20
19
  }
21
20
  },
22
- {
23
- paranoid: true,
21
+ options: {
24
22
  indexes: [
25
23
  {
26
24
  name: 'application_key',
27
25
  unique: true,
28
- fields: ['tenantId', 'applicationId', 'roleId', 'deletedAt']
26
+ fields: ['tenant_id', 'application_id', 'role_id', 'deleted_at']
29
27
  }
30
28
  ]
29
+ },
30
+ associate: ({ tenantRoleApplication, application }) => {
31
+ tenantRoleApplication.belongsTo(application, {
32
+ targetKey: 'uuid',
33
+ constraints: false
34
+ });
31
35
  }
32
- );
33
- tenantRoleApplication.associate = ({ tenantRoleApplication, application }) => {
34
- tenantRoleApplication.belongsTo(application);
35
36
  };
36
- return tenantRoleApplication;
37
37
  };