@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.
- package/README.md +101 -5
- package/index.js +13 -4
- package/libs/controllers/account.js +9 -15
- package/libs/controllers/admin.js +38 -15
- package/libs/controllers/adminPermission.js +42 -35
- package/libs/controllers/adminRole.js +13 -12
- package/libs/controllers/adminTenant.js +39 -36
- package/libs/controllers/tenant.js +51 -4
- package/libs/controllers/user.js +23 -1
- package/libs/models/admin-role.js +4 -8
- package/libs/models/application.js +16 -10
- package/libs/models/login-log.js +4 -8
- package/libs/models/permission.js +7 -9
- package/libs/models/tenant-application.js +8 -10
- package/libs/models/tenant-org.js +5 -9
- package/libs/models/tenant-permission.js +7 -9
- package/libs/models/tenant-role-application.js +14 -10
- package/libs/models/tenant-role-permission.js +10 -9
- package/libs/models/tenant-role.js +5 -9
- package/libs/models/tenant-share-group-permission.js +5 -9
- package/libs/models/tenant-share-group.js +5 -9
- package/libs/models/tenant-source-user-share-group.js +5 -9
- package/libs/models/tenant-token.js +7 -9
- package/libs/models/tenant-user-org.js +11 -10
- package/libs/models/tenant-user-role.js +11 -10
- package/libs/models/tenant-user-share-group.js +6 -10
- package/libs/models/tenant-user.js +35 -16
- package/libs/models/tenant.js +17 -9
- package/libs/models/user-account.js +17 -9
- package/libs/models/user.js +27 -17
- package/libs/models/verification-code.js +4 -8
- package/libs/services/account.js +34 -16
- package/libs/services/admin.js +38 -122
- package/libs/services/application.js +151 -0
- package/libs/services/permission.js +47 -145
- package/libs/services/tenant-invite.js +62 -0
- package/libs/services/tenant-org.js +97 -0
- package/libs/services/tenant-role.js +108 -0
- package/libs/services/tenant-user.js +566 -0
- package/libs/services/tenant.js +68 -512
- package/libs/services/user.js +69 -30
- package/package.json +3 -3
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
applicationId: {
|
|
10
|
-
type: DataTypes.
|
|
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: ['
|
|
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 = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
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 = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
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: ['
|
|
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 = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
applicationId: {
|
|
10
|
-
type: DataTypes.
|
|
9
|
+
type: DataTypes.UUID,
|
|
11
10
|
allowNull: false
|
|
12
11
|
},
|
|
13
12
|
roleId: {
|
|
@@ -19,15 +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: ['
|
|
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
|
-
|
|
36
|
+
};
|
|
33
37
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
permissionId: {
|
|
@@ -19,15 +18,17 @@ 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: 'permission_key',
|
|
27
25
|
unique: true,
|
|
28
|
-
fields: ['
|
|
26
|
+
fields: ['tenant_id', 'permission_id', 'role_id', 'deleted_at']
|
|
29
27
|
}
|
|
30
28
|
]
|
|
29
|
+
},
|
|
30
|
+
associate: ({ tenantRolePermission, permission }) => {
|
|
31
|
+
tenantRolePermission.belongsTo(permission, { constraints: false });
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
};
|
|
33
34
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
name: {
|
|
@@ -19,9 +18,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
19
18
|
defaultValue: 0 //0:用户自定义,1:系统默认
|
|
20
19
|
},
|
|
21
20
|
description: DataTypes.TEXT
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
paranoid: true
|
|
25
21
|
}
|
|
26
|
-
|
|
22
|
+
};
|
|
27
23
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
tenantShareGroupId: {
|
|
@@ -14,9 +13,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
14
13
|
type: DataTypes.INTEGER,
|
|
15
14
|
allowNull: false
|
|
16
15
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
};
|
|
22
18
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
name: {
|
|
@@ -14,9 +13,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
14
13
|
type: DataTypes.INTEGER,
|
|
15
14
|
defaultValue: 0
|
|
16
15
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
};
|
|
22
18
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
tenantUserId: {
|
|
@@ -14,9 +13,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
14
13
|
type: DataTypes.INTEGER,
|
|
15
14
|
allowNull: false
|
|
16
15
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
};
|
|
22
18
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
5
|
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
@@ -15,18 +14,17 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
15
14
|
type: DataTypes.INTEGER,
|
|
16
15
|
allowNull: false //10:邀请用户加入租户
|
|
17
16
|
},
|
|
18
|
-
|
|
17
|
+
createdTenantUserId: {
|
|
19
18
|
type: DataTypes.UUID
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
|
-
{
|
|
23
|
-
paranoid: true,
|
|
21
|
+
options: {
|
|
24
22
|
indexes: [
|
|
25
23
|
{
|
|
26
24
|
unique: true,
|
|
27
|
-
fields: ['
|
|
25
|
+
fields: ['tenant_id', 'token', 'type', 'deleted_at']
|
|
28
26
|
}
|
|
29
27
|
]
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
};
|
|
32
30
|
};
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
4
|
+
id: {
|
|
5
|
+
type: DataTypes.INTEGER,
|
|
6
|
+
autoIncrement: true,
|
|
7
|
+
primaryKey: true
|
|
8
|
+
},
|
|
5
9
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
10
|
+
type: DataTypes.UUID,
|
|
7
11
|
allowNull: false
|
|
8
12
|
},
|
|
9
13
|
tenantUserId: {
|
|
10
|
-
type: DataTypes.
|
|
14
|
+
type: DataTypes.UUID,
|
|
11
15
|
allowNull: false
|
|
12
16
|
},
|
|
13
17
|
tenantOrgId: {
|
|
14
18
|
type: DataTypes.INTEGER,
|
|
15
19
|
allowNull: false
|
|
16
20
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
};
|
|
22
23
|
};
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
4
|
+
id: {
|
|
5
|
+
type: DataTypes.INTEGER,
|
|
6
|
+
autoIncrement: true,
|
|
7
|
+
primaryKey: true
|
|
8
|
+
},
|
|
5
9
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
10
|
+
type: DataTypes.UUID,
|
|
7
11
|
allowNull: false
|
|
8
12
|
},
|
|
9
13
|
tenantUserId: {
|
|
10
|
-
type: DataTypes.
|
|
14
|
+
type: DataTypes.UUID,
|
|
11
15
|
allowNull: false
|
|
12
16
|
},
|
|
13
17
|
tenantRoleId: {
|
|
14
18
|
type: DataTypes.INTEGER,
|
|
15
19
|
allowNull: false
|
|
16
20
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
};
|
|
22
23
|
};
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
tenantId: {
|
|
6
|
-
type: DataTypes.
|
|
5
|
+
type: DataTypes.UUID,
|
|
7
6
|
allowNull: false
|
|
8
7
|
},
|
|
9
8
|
tenantUserId: {
|
|
10
|
-
type: DataTypes.
|
|
9
|
+
type: DataTypes.UUID,
|
|
11
10
|
allowNull: false
|
|
12
11
|
},
|
|
13
12
|
tenantShareGroupId: {
|
|
14
13
|
type: DataTypes.INTEGER,
|
|
15
14
|
allowNull: false
|
|
16
15
|
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
paranoid: true
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
};
|
|
22
18
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
id: {
|
|
6
|
-
type: DataTypes.
|
|
7
|
-
|
|
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
|
userId: {
|
|
11
14
|
type: DataTypes.UUID,
|
|
12
15
|
allowNull: false
|
|
@@ -36,21 +39,37 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
36
39
|
defaultValue: 0 //0:正常,11:已禁用,12:已关闭,
|
|
37
40
|
}
|
|
38
41
|
},
|
|
39
|
-
{
|
|
40
|
-
paranoid: true,
|
|
42
|
+
options: {
|
|
41
43
|
indexes: [
|
|
42
44
|
{
|
|
43
45
|
unique: true,
|
|
44
|
-
fields: ['
|
|
46
|
+
fields: ['uuid', 'deleted_at']
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
unique: true,
|
|
50
|
+
fields: ['tenant_id', 'user_id', 'deleted_at']
|
|
45
51
|
}
|
|
46
52
|
]
|
|
53
|
+
},
|
|
54
|
+
associate: ({ user, tenantRole, tenantUser, tenantUserRole, tenantOrg, tenantUserOrg }) => {
|
|
55
|
+
tenantUser.belongsToMany(tenantRole, {
|
|
56
|
+
through: tenantUserRole,
|
|
57
|
+
foreignKey: 'tenantUserId',
|
|
58
|
+
otherKey: 'tenantRoleId',
|
|
59
|
+
sourceKey: 'uuid',
|
|
60
|
+
constraints: false
|
|
61
|
+
});
|
|
62
|
+
tenantUser.belongsToMany(tenantOrg, {
|
|
63
|
+
through: tenantUserOrg,
|
|
64
|
+
foreignKey: 'tenantUserId',
|
|
65
|
+
otherKey: 'tenantOrgId',
|
|
66
|
+
sourceKey: 'uuid',
|
|
67
|
+
constraints: false
|
|
68
|
+
});
|
|
69
|
+
tenantUser.belongsTo(user, {
|
|
70
|
+
targetKey: 'uuid',
|
|
71
|
+
constraints: false
|
|
72
|
+
});
|
|
47
73
|
}
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
tenantUser.associate = ({ user, tenantRole, tenantUser, tenantUserRole, tenantOrg, tenantUserOrg }) => {
|
|
51
|
-
tenantUser.belongsToMany(tenantRole, { through: tenantUserRole });
|
|
52
|
-
tenantUser.belongsToMany(tenantOrg, { through: tenantUserOrg });
|
|
53
|
-
tenantUser.belongsTo(user);
|
|
54
74
|
};
|
|
55
|
-
return tenantUser;
|
|
56
75
|
};
|
package/libs/models/tenant.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
id: {
|
|
6
|
-
type: DataTypes.
|
|
7
|
-
|
|
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
|
name: {
|
|
11
14
|
type: DataTypes.STRING,
|
|
12
15
|
allowNull: false
|
|
@@ -31,8 +34,13 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
31
34
|
},
|
|
32
35
|
description: DataTypes.TEXT
|
|
33
36
|
},
|
|
34
|
-
{
|
|
35
|
-
|
|
37
|
+
options: {
|
|
38
|
+
indexes: [
|
|
39
|
+
{
|
|
40
|
+
unique: true,
|
|
41
|
+
fields: ['uuid', 'deleted_at']
|
|
42
|
+
}
|
|
43
|
+
]
|
|
36
44
|
}
|
|
37
|
-
|
|
45
|
+
};
|
|
38
46
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
id: {
|
|
6
|
-
type: DataTypes.
|
|
7
|
-
|
|
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
|
password: {
|
|
11
14
|
type: DataTypes.STRING,
|
|
12
15
|
allowNull: false
|
|
@@ -19,8 +22,13 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
19
22
|
type: DataTypes.UUID //用户修改密码时重新生成一条数据,该字段用于记录这个账号之前是属于哪个账号的
|
|
20
23
|
}
|
|
21
24
|
},
|
|
22
|
-
{
|
|
23
|
-
|
|
25
|
+
options: {
|
|
26
|
+
indexes: [
|
|
27
|
+
{
|
|
28
|
+
unique: true,
|
|
29
|
+
fields: ['uuid', 'deleted_at']
|
|
30
|
+
}
|
|
31
|
+
]
|
|
24
32
|
}
|
|
25
|
-
|
|
33
|
+
};
|
|
26
34
|
};
|
package/libs/models/user.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
id: {
|
|
6
|
-
type: DataTypes.
|
|
7
|
-
|
|
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
|
nickname: DataTypes.STRING,
|
|
11
14
|
email: DataTypes.STRING,
|
|
12
15
|
phone: DataTypes.STRING,
|
|
@@ -26,25 +29,32 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
26
29
|
birthday: DataTypes.DATE,
|
|
27
30
|
description: DataTypes.TEXT
|
|
28
31
|
},
|
|
29
|
-
{
|
|
30
|
-
paranoid: true,
|
|
32
|
+
options: {
|
|
31
33
|
indexes: [
|
|
32
34
|
{
|
|
33
35
|
unique: true,
|
|
34
|
-
fields: ['
|
|
36
|
+
fields: ['uuid', 'deleted_at']
|
|
35
37
|
},
|
|
36
38
|
{
|
|
37
39
|
unique: true,
|
|
38
|
-
fields: ['
|
|
40
|
+
fields: ['email', 'deleted_at']
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
unique: true,
|
|
44
|
+
fields: ['phone', 'deleted_at']
|
|
39
45
|
}
|
|
40
46
|
]
|
|
47
|
+
},
|
|
48
|
+
associate: ({ adminRole, user, tenant, tenantUser }) => {
|
|
49
|
+
user.hasOne(adminRole, { foreignKey: 'userId', sourceKey: 'uuid', constraints: false });
|
|
50
|
+
user.belongsToMany(tenant, {
|
|
51
|
+
through: { model: tenantUser, unique: false },
|
|
52
|
+
otherKey: 'tenantId',
|
|
53
|
+
foreignKey: 'userId',
|
|
54
|
+
targetKey: 'uuid',
|
|
55
|
+
sourceKey: 'uuid',
|
|
56
|
+
constraints: false
|
|
57
|
+
});
|
|
41
58
|
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
user.associate = ({ adminRole, user, tenant, tenantUser }) => {
|
|
45
|
-
user.hasOne(adminRole, { foreignKey: 'userId' });
|
|
46
|
-
user.belongsToMany(tenant, { through: { model: tenantUser, unique: false } });
|
|
47
59
|
};
|
|
48
|
-
|
|
49
|
-
return user;
|
|
50
60
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
{
|
|
1
|
+
module.exports = ({ DataTypes }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
5
4
|
name: {
|
|
6
5
|
type: DataTypes.STRING,
|
|
7
6
|
allowNull: false
|
|
@@ -18,9 +17,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
18
17
|
type: DataTypes.INTEGER,
|
|
19
18
|
defaultValue: 0 //0:未验证,1:已验证,2:已过期
|
|
20
19
|
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
paranoid: true
|
|
24
20
|
}
|
|
25
|
-
|
|
21
|
+
};
|
|
26
22
|
};
|