@kne/fastify-account 1.0.0-alpha.22 → 1.0.0-alpha.24
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 +28 -16
- package/libs/controllers/adminTenant.js +6 -2
- package/libs/controllers/adminTenantRole.js +2 -2
- package/libs/controllers/adminTenantUser.js +2 -1
- package/libs/controllers/tenant.js +24 -1
- package/libs/models/permission.js +1 -0
- package/libs/models/tenant-application.js +1 -0
- package/libs/models/tenant-permission.js +1 -0
- package/libs/models/tenant-role-application.js +1 -1
- package/libs/models/tenant-role-permission.js +1 -1
- package/libs/models/tenant-token.js +1 -0
- package/libs/models/user.js +1 -1
- package/libs/services/admin.js +3 -0
- package/libs/services/tenant-role.js +8 -1
- package/libs/services/tenant-user.js +19 -0
- package/libs/services/tenant.js +11 -0
- package/libs/services/user.js +20 -4
- package/package.json +1 -1
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.
|
|
25
|
+
title: "@kne/fastify-account v1.0.0-alpha.22"
|
|
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.
|
|
45
|
+
<h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.22</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
|
|
|
@@ -834,20 +834,6 @@ This operation does not require authentication
|
|
|
834
834
|
This operation does not require authentication
|
|
835
835
|
</aside>
|
|
836
836
|
|
|
837
|
-
## get__api_v1_account_tenant_getTenantUserInfo
|
|
838
|
-
|
|
839
|
-
`GET /api/v1/account/tenant/getTenantUserInfo`
|
|
840
|
-
|
|
841
|
-
<h3 id="get__api_v1_account_tenant_gettenantuserinfo-responses">Responses</h3>
|
|
842
|
-
|
|
843
|
-
|Status|Meaning|Description|Schema|
|
|
844
|
-
|---|---|---|---|
|
|
845
|
-
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
|
|
846
|
-
|
|
847
|
-
<aside class="success">
|
|
848
|
-
This operation does not require authentication
|
|
849
|
-
</aside>
|
|
850
|
-
|
|
851
837
|
## post__api_v1_account_tenant_addOrg
|
|
852
838
|
|
|
853
839
|
`POST /api/v1/account/tenant/addOrg`
|
|
@@ -2681,6 +2667,31 @@ This operation does not require authentication
|
|
|
2681
2667
|
This operation does not require authentication
|
|
2682
2668
|
</aside>
|
|
2683
2669
|
|
|
2670
|
+
## get__api_v1_account_tenant_getTenantUserInfo
|
|
2671
|
+
|
|
2672
|
+
`GET /api/v1/account/tenant/getTenantUserInfo`
|
|
2673
|
+
|
|
2674
|
+
*获取租户用户所有操作日志列表*
|
|
2675
|
+
|
|
2676
|
+
<h3 id="get__api_v1_account_tenant_gettenantuserinfo-parameters">Parameters</h3>
|
|
2677
|
+
|
|
2678
|
+
|Name|In|Type|Required|Description|
|
|
2679
|
+
|---|---|---|---|---|
|
|
2680
|
+
|filter|path|object|true|none|
|
|
2681
|
+
|type|path|string|true|none|
|
|
2682
|
+
|perPage|path|number|true|none|
|
|
2683
|
+
|currentPage|path|number|true|none|
|
|
2684
|
+
|
|
2685
|
+
<h3 id="get__api_v1_account_tenant_gettenantuserinfo-responses">Responses</h3>
|
|
2686
|
+
|
|
2687
|
+
|Status|Meaning|Description|Schema|
|
|
2688
|
+
|---|---|---|---|
|
|
2689
|
+
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
|
|
2690
|
+
|
|
2691
|
+
<aside class="success">
|
|
2692
|
+
This operation does not require authentication
|
|
2693
|
+
</aside>
|
|
2694
|
+
|
|
2684
2695
|
<h1 id="-kne-fastify-account--">管理后台-权限</h1>
|
|
2685
2696
|
|
|
2686
2697
|
## post__api_v1_account_admin_addApplication
|
|
@@ -3391,6 +3402,7 @@ This operation does not require authentication
|
|
|
3391
3402
|
|Name|In|Type|Required|Description|
|
|
3392
3403
|
|---|---|---|---|---|
|
|
3393
3404
|
|name|query|string|false|租户名|
|
|
3405
|
+
|status|query|number|false|状态|
|
|
3394
3406
|
|serviceStartTime|query|string(date-time)|false|服务开始时间|
|
|
3395
3407
|
|serviceEndTime|query|string(date-time)|false|服务结束时间|
|
|
3396
3408
|
|perPage|query|number|false|每页条数|
|
|
@@ -16,6 +16,10 @@ module.exports = fp(async (fastify, options) => {
|
|
|
16
16
|
type: 'string',
|
|
17
17
|
description: '租户名'
|
|
18
18
|
},
|
|
19
|
+
status: {
|
|
20
|
+
type: 'number',
|
|
21
|
+
description: '状态'
|
|
22
|
+
},
|
|
19
23
|
serviceStartTime: {
|
|
20
24
|
type: 'string',
|
|
21
25
|
format: 'date-time',
|
|
@@ -70,7 +74,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
70
74
|
}
|
|
71
75
|
},
|
|
72
76
|
async request => {
|
|
73
|
-
const { name, perPage, currentPage } = Object.assign(
|
|
77
|
+
const { name, status, perPage, currentPage } = Object.assign(
|
|
74
78
|
{
|
|
75
79
|
perPage: 20,
|
|
76
80
|
currentPage: 1
|
|
@@ -78,7 +82,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
78
82
|
request.query
|
|
79
83
|
);
|
|
80
84
|
return await services.tenant.getAllTenantList({
|
|
81
|
-
filter: { name },
|
|
85
|
+
filter: { name, status },
|
|
82
86
|
perPage,
|
|
83
87
|
currentPage
|
|
84
88
|
});
|
|
@@ -25,7 +25,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
async request => {
|
|
28
|
-
const { filter, tenantId, perPage, currentPage } = Object.assign(
|
|
28
|
+
const { filter, tenantId, withoutDefaultRole, perPage, currentPage } = Object.assign(
|
|
29
29
|
{
|
|
30
30
|
perPage: 20,
|
|
31
31
|
currentPage: 1,
|
|
@@ -33,7 +33,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
33
33
|
},
|
|
34
34
|
request.query
|
|
35
35
|
);
|
|
36
|
-
return await services.tenantRole.getTenantRoleList({ tenantId, perPage, currentPage, filter });
|
|
36
|
+
return await services.tenantRole.getTenantRoleList({ tenantId, withoutDefaultRole, perPage, currentPage, filter });
|
|
37
37
|
}
|
|
38
38
|
);
|
|
39
39
|
|
|
@@ -15,7 +15,8 @@ module.exports = fp(async (fastify, options) => {
|
|
|
15
15
|
filter: {
|
|
16
16
|
type: 'object',
|
|
17
17
|
properties: {
|
|
18
|
-
name: { type: 'string' }
|
|
18
|
+
name: { type: 'string' },
|
|
19
|
+
roleIds: { type: 'array', items: { type: 'number' }, default: [] }
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
currentPage: { type: 'number' },
|
|
@@ -10,11 +10,34 @@ module.exports = fp(async (fastify, options) => {
|
|
|
10
10
|
return await services.tenantUser.getUserTenant(request.authenticatePayload);
|
|
11
11
|
}
|
|
12
12
|
);
|
|
13
|
+
fastify.get(
|
|
14
|
+
`${options.prefix}/tenant/getTenantInfo`,
|
|
15
|
+
{
|
|
16
|
+
onRequest: [authenticate.user]
|
|
17
|
+
},
|
|
18
|
+
async request => {
|
|
19
|
+
return await services.tenant.getTenantInfo(request.query);
|
|
20
|
+
}
|
|
21
|
+
);
|
|
13
22
|
|
|
14
23
|
fastify.get(
|
|
15
24
|
`${options.prefix}/tenant/getTenantUserInfo`,
|
|
16
25
|
{
|
|
17
|
-
onRequest: [authenticate.user, authenticate.tenant]
|
|
26
|
+
onRequest: [authenticate.user, authenticate.tenant],
|
|
27
|
+
schema: {
|
|
28
|
+
tags: ['管理后台'],
|
|
29
|
+
summary: '获取租户用户所有操作日志列表',
|
|
30
|
+
params: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
required: [],
|
|
33
|
+
properties: {
|
|
34
|
+
filter: { type: 'object' },
|
|
35
|
+
type: { type: 'string' },
|
|
36
|
+
perPage: { type: 'number' },
|
|
37
|
+
currentPage: { type: 'number' }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
18
41
|
},
|
|
19
42
|
async request => {
|
|
20
43
|
return request.tenantInfo;
|
package/libs/models/user.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = ({ DataTypes }) => {
|
|
|
19
19
|
},
|
|
20
20
|
status: {
|
|
21
21
|
type: DataTypes.INTEGER,
|
|
22
|
-
defaultValue: 0 //0:正常,
|
|
22
|
+
defaultValue: 0 //0:正常,1:初始化未激活,需要用户设置密码后使用,11:已禁用,12:已关闭,
|
|
23
23
|
},
|
|
24
24
|
currentTenantId: {
|
|
25
25
|
type: DataTypes.UUID
|
package/libs/services/admin.js
CHANGED
|
@@ -29,6 +29,9 @@ module.exports = fp(async (fastify, options) => {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
const addUser = async ({ avatar, nickname, phone, email, password, description }) => {
|
|
32
|
+
if (!email && !phone) {
|
|
33
|
+
throw new Error('请输入邮箱或手机号');
|
|
34
|
+
}
|
|
32
35
|
return await services.user.addUser({
|
|
33
36
|
avatar,
|
|
34
37
|
nickname,
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
const isNil = require('lodash/isNil');
|
|
3
|
+
const isEmpty = require('lodash/isEmpty');
|
|
4
|
+
|
|
3
5
|
module.exports = fp(async (fastify, options) => {
|
|
4
6
|
const { models, services } = fastify.account;
|
|
5
7
|
const { Op } = fastify.sequelize.Sequelize;
|
|
6
8
|
|
|
7
|
-
const getTenantRoleList = async ({ tenantId, currentPage, perPage, filter }) => {
|
|
9
|
+
const getTenantRoleList = async ({ tenantId, withoutDefaultRole, currentPage, perPage, filter }) => {
|
|
8
10
|
const queryFilter = {};
|
|
9
11
|
if (!isNil(filter?.type)) {
|
|
10
12
|
queryFilter.type = filter.type;
|
|
11
13
|
}
|
|
14
|
+
if (!isEmpty(withoutDefaultRole) && withoutDefaultRole === 'true') {
|
|
15
|
+
queryFilter.type = {
|
|
16
|
+
[Op.not]: 1
|
|
17
|
+
};
|
|
18
|
+
}
|
|
12
19
|
const { count, rows } = await models.tenantRole.findAndCountAll({
|
|
13
20
|
where: Object.assign({}, queryFilter, { tenantId }),
|
|
14
21
|
offset: perPage * (currentPage - 1),
|
|
@@ -4,6 +4,7 @@ const groupBy = require('lodash/groupBy');
|
|
|
4
4
|
const { Unauthorized } = require('http-errors');
|
|
5
5
|
const pick = require('lodash/pick');
|
|
6
6
|
const isNil = require('lodash/isNil');
|
|
7
|
+
const isEmpty = require('lodash/isEmpty');
|
|
7
8
|
module.exports = fp(async (fastify, options) => {
|
|
8
9
|
const { models, services } = fastify.account;
|
|
9
10
|
const { Op } = fastify.sequelize.Sequelize;
|
|
@@ -483,6 +484,24 @@ module.exports = fp(async (fastify, options) => {
|
|
|
483
484
|
};
|
|
484
485
|
}
|
|
485
486
|
});
|
|
487
|
+
if (filter && !isEmpty(filter.status)) {
|
|
488
|
+
queryFilter['status'] = {
|
|
489
|
+
[Op.eq]: filter.status
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
if (!isEmpty(filter.roleIds)) {
|
|
493
|
+
const defaultTenant = await models.tenantUserRole.findAll({
|
|
494
|
+
where: {
|
|
495
|
+
tenantRoleId: {
|
|
496
|
+
[Op.in]: !isEmpty(filter.roleIds) ? filter.roleIds : []
|
|
497
|
+
},
|
|
498
|
+
tenantId: tenantId
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
queryFilter['uuid'] = {
|
|
502
|
+
[Op.in]: (defaultTenant || []).map(item => item.tenantUserId)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
486
505
|
|
|
487
506
|
const { count, rows } = await models.tenantUser.findAndCountAll({
|
|
488
507
|
include: [models.tenantRole, models.tenantOrg, models.user],
|
package/libs/services/tenant.js
CHANGED
|
@@ -24,6 +24,11 @@ module.exports = fp(async (fastify, options) => {
|
|
|
24
24
|
|
|
25
25
|
return Object.assign({}, tenant.get({ plain: true }), { id: tenant.uuid });
|
|
26
26
|
};
|
|
27
|
+
const getTenantInfo = async ({ id }) => {
|
|
28
|
+
const tenantInfo = await services.tenant.getTenant({ id: id });
|
|
29
|
+
// console.log('getTenantInfo=======>\n', tenantInfo);
|
|
30
|
+
return tenantInfo;
|
|
31
|
+
};
|
|
27
32
|
|
|
28
33
|
const closeTenant = async ({ tenantId }) => {
|
|
29
34
|
const tenant = await getTenantInstance({ id: tenantId });
|
|
@@ -83,6 +88,11 @@ module.exports = fp(async (fastify, options) => {
|
|
|
83
88
|
[fastify.sequelize.Sequelize.Op.like]: `%${filter.name}%`
|
|
84
89
|
};
|
|
85
90
|
}
|
|
91
|
+
if (filter?.status) {
|
|
92
|
+
queryFilter.status = {
|
|
93
|
+
[fastify.sequelize.Sequelize.Op.like]: filter.status
|
|
94
|
+
};
|
|
95
|
+
}
|
|
86
96
|
|
|
87
97
|
if (filter?.serviceStartTime) {
|
|
88
98
|
queryFilter.serviceStartTime = {
|
|
@@ -123,6 +133,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
123
133
|
services.tenant = {
|
|
124
134
|
getTenantInstance,
|
|
125
135
|
getTenant,
|
|
136
|
+
getTenantInfo,
|
|
126
137
|
closeTenant,
|
|
127
138
|
openTenant,
|
|
128
139
|
saveTenant,
|
package/libs/services/user.js
CHANGED
|
@@ -3,6 +3,7 @@ const { Unauthorized } = require('http-errors');
|
|
|
3
3
|
const get = require('lodash/get');
|
|
4
4
|
const pick = require('lodash/pick');
|
|
5
5
|
const isNil = require('lodash/isNil');
|
|
6
|
+
const isEmpty = require('lodash/isEmpty');
|
|
6
7
|
|
|
7
8
|
function userNameIsEmail(username) {
|
|
8
9
|
return /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(username);
|
|
@@ -107,8 +108,10 @@ module.exports = fp(async (fastify, options) => {
|
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
const saveUser = async ({ id, ...otherInfo }) => {
|
|
111
|
+
if (!otherInfo.email && !otherInfo.phone) {
|
|
112
|
+
throw new Error('请输入邮箱或手机号');
|
|
113
|
+
}
|
|
110
114
|
const user = await getUserInstance({ id });
|
|
111
|
-
|
|
112
115
|
if ((await accountIsExists({ phone: otherInfo.phone, email: otherInfo.email }, user)) > 0) {
|
|
113
116
|
throw new Error('手机号或者邮箱都不能重复');
|
|
114
117
|
}
|
|
@@ -142,20 +145,33 @@ module.exports = fp(async (fastify, options) => {
|
|
|
142
145
|
};
|
|
143
146
|
|
|
144
147
|
const getAllUserList = async ({ filter, perPage, currentPage }) => {
|
|
145
|
-
const queryFilter = {}
|
|
148
|
+
const queryFilter = {},
|
|
149
|
+
roleQueryFilter = {};
|
|
146
150
|
|
|
147
|
-
['nickname'].forEach(key => {
|
|
151
|
+
['nickname', 'email', 'phone'].forEach(key => {
|
|
148
152
|
if (filter && filter[key]) {
|
|
149
153
|
queryFilter[key] = {
|
|
150
154
|
[Op.like]: `%${filter[key]}%`
|
|
151
155
|
};
|
|
152
156
|
}
|
|
153
157
|
});
|
|
158
|
+
if (filter && !isEmpty(filter.status)) {
|
|
159
|
+
queryFilter['status'] = {
|
|
160
|
+
[Op.eq]: filter.status
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (!isEmpty(filter?.isSuperAdmin)) {
|
|
164
|
+
roleQueryFilter['role'] = {
|
|
165
|
+
[Op.eq]: filter.isSuperAdmin === 'false' ? 'Common' : 'SuperAdmin'
|
|
166
|
+
};
|
|
167
|
+
}
|
|
154
168
|
const { count, rows } = await models.user.findAndCountAll({
|
|
155
169
|
include: [
|
|
156
170
|
{
|
|
157
171
|
attributes: ['role'],
|
|
158
|
-
model: models.adminRole
|
|
172
|
+
model: models.adminRole,
|
|
173
|
+
where: roleQueryFilter,
|
|
174
|
+
required: !!roleQueryFilter.role
|
|
159
175
|
},
|
|
160
176
|
{
|
|
161
177
|
model: models.tenant
|