@drax/identity-back 0.0.21 → 0.0.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/dist/factory/RoleServiceFactory.js +0 -1
- package/dist/factory/TenantServiceFactory.js +0 -1
- package/dist/factory/UserServiceFactory.js +0 -1
- package/dist/graphql/resolvers/role.resolvers.js +2 -2
- package/dist/graphql/resolvers/tenant.resolvers.js +2 -2
- package/dist/graphql/resolvers/user.resolvers.js +8 -2
- package/dist/graphql/types/role.graphql +1 -1
- package/dist/graphql/types/tenant.graphql +1 -1
- package/dist/graphql/types/user.graphql +1 -1
- package/dist/models/UserModel.js +8 -16
- package/dist/repository/mongo/RoleMongoRepository.js +1 -1
- package/dist/repository/mongo/TenantMongoRepository.js +1 -1
- package/dist/repository/mongo/UserMongoRepository.js +1 -1
- package/dist/repository/sqlite/RoleSqliteRepository.js +33 -33
- package/dist/repository/sqlite/TenantSqliteRepository.js +3 -14
- package/dist/repository/sqlite/UserSqliteRepository.js +1 -1
- package/dist/routes/RoleRoutes.js +3 -1
- package/dist/routes/TenantRoutes.js +3 -1
- package/dist/routes/UserRoutes.js +9 -1
- package/dist/services/RoleService.js +2 -2
- package/dist/services/TenantService.js +2 -2
- package/dist/services/UserService.js +4 -2
- package/package.json +5 -2
- package/src/factory/RoleServiceFactory.ts +0 -1
- package/src/factory/TenantServiceFactory.ts +0 -1
- package/src/factory/UserServiceFactory.ts +0 -1
- package/src/graphql/resolvers/role.resolvers.ts +2 -2
- package/src/graphql/resolvers/tenant.resolvers.ts +2 -2
- package/src/graphql/resolvers/user.resolvers.ts +8 -2
- package/src/graphql/types/role.graphql +1 -1
- package/src/graphql/types/tenant.graphql +1 -1
- package/src/graphql/types/user.graphql +1 -1
- package/src/index.ts +6 -9
- package/src/interfaces/IRoleRepository.ts +5 -10
- package/src/interfaces/ITenantRepository.ts +4 -10
- package/src/interfaces/IUserRepository.ts +6 -12
- package/src/middleware/jwtMiddleware.ts +1 -1
- package/src/middleware/rbacMiddleware.ts +1 -2
- package/src/models/RoleModel.ts +1 -1
- package/src/models/TenantModel.ts +1 -1
- package/src/models/UserGroupModel.ts +1 -1
- package/src/models/UserModel.ts +9 -17
- package/src/rbac/Rbac.ts +1 -2
- package/src/repository/mongo/RoleMongoRepository.ts +14 -8
- package/src/repository/mongo/TenantMongoRepository.ts +14 -7
- package/src/repository/mongo/UserMongoRepository.ts +14 -9
- package/src/repository/sqlite/RoleSqliteRepository.ts +53 -44
- package/src/repository/sqlite/TenantSqliteRepository.ts +15 -23
- package/src/repository/sqlite/UserSqliteRepository.ts +15 -10
- package/src/routes/RoleRoutes.ts +7 -4
- package/src/routes/TenantRoutes.ts +7 -5
- package/src/routes/UserRoutes.ts +13 -4
- package/src/services/RoleService.ts +15 -8
- package/src/services/TenantService.ts +15 -9
- package/src/services/UserService.ts +15 -7
- package/src/setup/CreateOrUpdateRole.ts +2 -2
- package/src/setup/CreateUserIfNotExist.ts +1 -1
- package/test/data-obj/roles/admin-mongo-role.ts +1 -1
- package/test/initializers/RoleMongoInitializer.ts +1 -1
- package/test/initializers/RoleSqliteInitializer.ts +1 -1
- package/test/repository/mongo/role-mongo-repository.test.ts +1 -1
- package/test/repository/mongo/user-mongo-repository.test.ts +1 -1
- package/test/repository/sqlite/role-sqlite-repository.test.ts +1 -1
- package/test/repository/sqlite/user-sqlite-repository.test.ts +2 -2
- package/test/service/mock-service.test.ts +2 -2
- package/test/service/role-service.test.ts +2 -2
- package/test/service/user-service.test.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/types/factory/RoleServiceFactory.d.ts.map +1 -1
- package/types/factory/TenantServiceFactory.d.ts.map +1 -1
- package/types/factory/UserServiceFactory.d.ts.map +1 -1
- package/types/graphql/resolvers/role.resolvers.d.ts +10 -8
- package/types/graphql/resolvers/role.resolvers.d.ts.map +1 -1
- package/types/graphql/resolvers/tenant.resolvers.d.ts +10 -8
- package/types/graphql/resolvers/tenant.resolvers.d.ts.map +1 -1
- package/types/graphql/resolvers/user.resolvers.d.ts +8 -6
- package/types/graphql/resolvers/user.resolvers.d.ts.map +1 -1
- package/types/index.d.ts +3 -5
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/IRoleRepository.d.ts +4 -10
- package/types/interfaces/IRoleRepository.d.ts.map +1 -1
- package/types/interfaces/ITenantRepository.d.ts +4 -10
- package/types/interfaces/ITenantRepository.d.ts.map +1 -1
- package/types/interfaces/IUserRepository.d.ts +5 -11
- package/types/interfaces/IUserRepository.d.ts.map +1 -1
- package/types/middleware/rbacMiddleware.d.ts.map +1 -1
- package/types/models/RoleModel.d.ts +1 -1
- package/types/models/RoleModel.d.ts.map +1 -1
- package/types/models/TenantModel.d.ts +1 -1
- package/types/models/TenantModel.d.ts.map +1 -1
- package/types/models/UserGroupModel.d.ts +1 -1
- package/types/models/UserGroupModel.d.ts.map +1 -1
- package/types/models/UserModel.d.ts +1 -1
- package/types/models/UserModel.d.ts.map +1 -1
- package/types/rbac/Rbac.d.ts +1 -2
- package/types/rbac/Rbac.d.ts.map +1 -1
- package/types/repository/mongo/RoleMongoRepository.d.ts +7 -8
- package/types/repository/mongo/RoleMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/TenantMongoRepository.d.ts +7 -8
- package/types/repository/mongo/TenantMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/UserMongoRepository.d.ts +7 -9
- package/types/repository/mongo/UserMongoRepository.d.ts.map +1 -1
- package/types/repository/sqlite/RoleSqliteRepository.d.ts +10 -11
- package/types/repository/sqlite/RoleSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/TenantSqliteRepository.d.ts +7 -8
- package/types/repository/sqlite/TenantSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/UserSqliteRepository.d.ts +9 -12
- package/types/repository/sqlite/UserSqliteRepository.d.ts.map +1 -1
- package/types/routes/RoleRoutes.d.ts.map +1 -1
- package/types/routes/TenantRoutes.d.ts.map +1 -1
- package/types/routes/UserRoutes.d.ts.map +1 -1
- package/types/services/RoleService.d.ts +7 -7
- package/types/services/RoleService.d.ts.map +1 -1
- package/types/services/TenantService.d.ts +7 -7
- package/types/services/TenantService.d.ts.map +1 -1
- package/types/services/UserService.d.ts +6 -6
- package/types/services/UserService.d.ts.map +1 -1
- package/types/setup/CreateOrUpdateRole.d.ts +2 -2
- package/types/setup/CreateOrUpdateRole.d.ts.map +1 -1
- package/types/setup/CreateUserIfNotExist.d.ts +1 -1
- package/types/setup/CreateUserIfNotExist.d.ts.map +1 -1
- package/src/interfaces/IID.ts +0 -5
- package/src/interfaces/IJwtUser.ts +0 -7
- package/src/interfaces/IRole.ts +0 -21
- package/src/interfaces/ITenant.ts +0 -9
- package/src/interfaces/IUser.ts +0 -48
- package/src/interfaces/IUserGroup.ts +0 -11
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {IUser, IUserCreate, IUserUpdate} from "
|
|
1
|
+
import {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
|
|
2
2
|
import sqlite from "better-sqlite3";
|
|
3
3
|
import {randomUUID} from "node:crypto";
|
|
4
4
|
import {UUID} from "crypto";
|
|
5
5
|
import {IUserRepository} from "../../interfaces/IUserRepository";
|
|
6
|
-
import
|
|
6
|
+
import {IDraxPaginateResult, IDraxPaginateOptions} from "@drax/common-share";
|
|
7
7
|
import { SqliteErrorToValidationError, ValidationError} from "@drax/common-back";
|
|
8
8
|
import RoleSqliteRepository from "./RoleSqliteRepository.js";
|
|
9
9
|
import TenantSqliteRepository from "./TenantSqliteRepository.js";
|
|
10
|
-
import {IID} from "../../interfaces/IID";
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
const userTableSQL: string = `
|
|
@@ -81,7 +80,7 @@ class UserSqliteRepository implements IUserRepository {
|
|
|
81
80
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
async update(id:
|
|
83
|
+
async update(id: string, userData: IUserUpdate): Promise<IUser> {
|
|
85
84
|
try {
|
|
86
85
|
if (!await this.findRoleById(userData.role)) {
|
|
87
86
|
throw new ValidationError([{field: 'role', reason: 'validation.notfound', value: userData.role}])
|
|
@@ -103,7 +102,7 @@ class UserSqliteRepository implements IUserRepository {
|
|
|
103
102
|
return this.findById(id)
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
async delete(id:
|
|
105
|
+
async delete(id: string): Promise<boolean> {
|
|
107
106
|
const stmt = this.db.prepare('DELETE FROM users WHERE id = ?');
|
|
108
107
|
stmt.run(id);
|
|
109
108
|
return true
|
|
@@ -115,7 +114,7 @@ class UserSqliteRepository implements IUserRepository {
|
|
|
115
114
|
return true
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
async findById(id:
|
|
117
|
+
async findById(id: string): Promise<IUser> {
|
|
119
118
|
const user = this.db.prepare('SELECT * FROM users WHERE id = ?').get(id);
|
|
120
119
|
if (!user) {
|
|
121
120
|
return null
|
|
@@ -135,7 +134,13 @@ class UserSqliteRepository implements IUserRepository {
|
|
|
135
134
|
return user
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
async paginate(
|
|
137
|
+
async paginate({
|
|
138
|
+
page= 1,
|
|
139
|
+
limit= 5,
|
|
140
|
+
orderBy= '',
|
|
141
|
+
orderDesc= false,
|
|
142
|
+
search= '',
|
|
143
|
+
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<IUser>> {
|
|
139
144
|
|
|
140
145
|
const offset = page > 1 ? (page - 1) * limit : 0
|
|
141
146
|
|
|
@@ -186,15 +191,15 @@ class UserSqliteRepository implements IUserRepository {
|
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
|
|
189
|
-
async findRoleById(id:
|
|
194
|
+
async findRoleById(id: string) {
|
|
190
195
|
return await this.roleRepository.findById(id)
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
async findTenantById(id:
|
|
198
|
+
async findTenantById(id: string) {
|
|
194
199
|
return await this.tenantRepository.findById(id)
|
|
195
200
|
}
|
|
196
201
|
|
|
197
|
-
async changePassword(id:
|
|
202
|
+
async changePassword(id: string, password: string): Promise<boolean> {
|
|
198
203
|
const stmt = this.db.prepare(`UPDATE users
|
|
199
204
|
SET password = @password
|
|
200
205
|
WHERE id = @id `);
|
package/src/routes/RoleRoutes.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValidationError} from "@drax/common-back";
|
|
2
2
|
import RoleServiceFactory from "../factory/RoleServiceFactory.js";
|
|
3
|
-
import {IRole} from "
|
|
3
|
+
import {IRole} from "@drax/identity-share";
|
|
4
4
|
import {IdentityPermissions} from "../permissions/IdentityPermissions.js";
|
|
5
5
|
import {PermissionService} from "../services/PermissionService.js";
|
|
6
6
|
import UnauthorizedError from "../errors/UnauthorizedError.js";
|
|
7
|
+
import {IDraxPaginateResult} from "@drax/common-share";
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
@@ -95,14 +96,16 @@ async function RoleRoutes(fastify, options) {
|
|
|
95
96
|
}
|
|
96
97
|
})
|
|
97
98
|
|
|
98
|
-
fastify.get('/api/roles', async (request, reply): Promise<
|
|
99
|
+
fastify.get('/api/roles', async (request, reply): Promise<IDraxPaginateResult<IRole>> => {
|
|
99
100
|
try {
|
|
100
101
|
request.rbac.assertPermission(IdentityPermissions.ViewRole)
|
|
101
102
|
const page = request.query.page
|
|
102
103
|
const limit = request.query.limit
|
|
104
|
+
const orderBy = request.query.orderBy
|
|
105
|
+
const orderDesc = request.query.orderDesc
|
|
103
106
|
const search = request.query.search
|
|
104
107
|
const roleService = RoleServiceFactory()
|
|
105
|
-
let paginateResult = await roleService.paginate(page, limit, search)
|
|
108
|
+
let paginateResult = await roleService.paginate({page, limit, search, orderBy, orderDesc})
|
|
106
109
|
return paginateResult
|
|
107
110
|
} catch (e) {
|
|
108
111
|
console.error(e)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValidationError} from "@drax/common-back";
|
|
2
2
|
import TenantServiceFactory from "../factory/TenantServiceFactory.js";
|
|
3
|
-
import {ITenant} from "
|
|
3
|
+
import {ITenant} from "@drax/identity-share";
|
|
4
4
|
import {IdentityPermissions} from "../permissions/IdentityPermissions.js";
|
|
5
|
-
import {PermissionService} from "../services/PermissionService.js";
|
|
6
5
|
import UnauthorizedError from "../errors/UnauthorizedError.js";
|
|
6
|
+
import {IDraxPaginateResult} from "@drax/common-share";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -78,14 +78,16 @@ async function TenantRoutes(fastify, options) {
|
|
|
78
78
|
}
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
fastify.get('/api/tenants', async (request, reply): Promise<
|
|
81
|
+
fastify.get('/api/tenants', async (request, reply): Promise<IDraxPaginateResult<ITenant>> => {
|
|
82
82
|
try {
|
|
83
83
|
request.rbac.assertPermission(IdentityPermissions.ViewTenant)
|
|
84
84
|
const page = request.query.page
|
|
85
85
|
const limit = request.query.limit
|
|
86
|
+
const orderBy = request.query.orderBy
|
|
87
|
+
const orderDesc = request.query.orderDesc
|
|
86
88
|
const search = request.query.search
|
|
87
89
|
const tenantService = TenantServiceFactory()
|
|
88
|
-
let paginateResult = await tenantService.paginate(page, limit, search)
|
|
90
|
+
let paginateResult = await tenantService.paginate({page, limit,orderBy, orderDesc, search})
|
|
89
91
|
return paginateResult
|
|
90
92
|
} catch (e) {
|
|
91
93
|
console.error(e)
|
package/src/routes/UserRoutes.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import UserServiceFactory from "../factory/UserServiceFactory.js";
|
|
2
|
-
import {IUser} from "
|
|
3
|
-
import {
|
|
2
|
+
import {IUser} from "@drax/identity-share";
|
|
3
|
+
import {ValidationError} from "@drax/common-back";
|
|
4
4
|
import {IdentityPermissions} from "../permissions/IdentityPermissions.js";
|
|
5
5
|
import UnauthorizedError from "../errors/UnauthorizedError.js";
|
|
6
6
|
import BadCredentialsError from "../errors/BadCredentialsError.js";
|
|
7
|
+
import {IDraxPaginateResult} from "@drax/common-share";
|
|
7
8
|
|
|
8
9
|
async function UserRoutes(fastify, options) {
|
|
9
10
|
fastify.post('/api/auth', async (request, reply) => {
|
|
@@ -53,19 +54,21 @@ async function UserRoutes(fastify, options) {
|
|
|
53
54
|
|
|
54
55
|
})
|
|
55
56
|
|
|
56
|
-
fastify.get('/api/users', async (request, reply): Promise<
|
|
57
|
+
fastify.get('/api/users', async (request, reply): Promise<IDraxPaginateResult<IUser>> => {
|
|
57
58
|
|
|
58
59
|
try {
|
|
59
60
|
request.rbac.assertPermission(IdentityPermissions.ViewUser)
|
|
60
61
|
const page = request.query.page
|
|
61
62
|
const limit = request.query.limit
|
|
63
|
+
const orderBy = request.query.orderBy
|
|
64
|
+
const orderDesc = request.query.orderDesc
|
|
62
65
|
const search = request.query.search
|
|
63
66
|
const userService = UserServiceFactory()
|
|
64
67
|
const filters = []
|
|
65
68
|
if(request.rbac.getAuthUser.tenantId){
|
|
66
69
|
filters.push({field: 'tenant', operator: '$eq', value: request.rbac.getAuthUser.tenantId})
|
|
67
70
|
}
|
|
68
|
-
let paginateResult = await userService.paginate(page, limit, search, filters)
|
|
71
|
+
let paginateResult = await userService.paginate({page, limit, orderBy, orderDesc, search, filters})
|
|
69
72
|
return paginateResult
|
|
70
73
|
} catch (e) {
|
|
71
74
|
console.log("/api/users",e)
|
|
@@ -87,6 +90,9 @@ async function UserRoutes(fastify, options) {
|
|
|
87
90
|
request.rbac.assertPermission(IdentityPermissions.CreateUser)
|
|
88
91
|
const payload = request.body
|
|
89
92
|
const userService = UserServiceFactory()
|
|
93
|
+
if(request.rbac.getAuthUser.tenantId){
|
|
94
|
+
payload.tenant = request.rbac.getAuthUser.tenantId
|
|
95
|
+
}
|
|
90
96
|
let user = await userService.create(payload)
|
|
91
97
|
return user
|
|
92
98
|
} catch (e) {
|
|
@@ -110,6 +116,9 @@ async function UserRoutes(fastify, options) {
|
|
|
110
116
|
const id = request.params.id
|
|
111
117
|
const payload = request.body
|
|
112
118
|
const userService = UserServiceFactory()
|
|
119
|
+
if(request.rbac.getAuthUser.tenantId){
|
|
120
|
+
payload.tenant = request.rbac.getAuthUser.tenantId
|
|
121
|
+
}
|
|
113
122
|
let user = await userService.update(id, payload)
|
|
114
123
|
return user
|
|
115
124
|
} catch (e) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {IRole} from "../interfaces/IRole";
|
|
2
1
|
import {IRoleRepository} from "../interfaces/IRoleRepository";
|
|
3
|
-
import {
|
|
2
|
+
import { ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
4
3
|
import {roleSchema} from "../zod/RoleZod.js";
|
|
5
4
|
import {ZodError} from "zod";
|
|
6
5
|
import UnauthorizedError from "../errors/UnauthorizedError.js";
|
|
6
|
+
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
|
|
7
|
+
import {IRoleBase, IRole} from "@drax/identity-share";
|
|
7
8
|
|
|
8
9
|
class RoleService {
|
|
9
10
|
|
|
@@ -14,7 +15,7 @@ class RoleService {
|
|
|
14
15
|
console.log("RoleService constructor")
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
async create(roleData:
|
|
18
|
+
async create(roleData: IRoleBase): Promise<IRole> {
|
|
18
19
|
try {
|
|
19
20
|
roleData.name = roleData?.name?.trim()
|
|
20
21
|
await roleSchema.parseAsync(roleData)
|
|
@@ -28,7 +29,7 @@ class RoleService {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
async update(id:
|
|
32
|
+
async update(id: string, roleData: IRoleBase) {
|
|
32
33
|
try {
|
|
33
34
|
roleData.name = roleData?.name?.trim()
|
|
34
35
|
await roleSchema.parseAsync(roleData)
|
|
@@ -42,13 +43,13 @@ class RoleService {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
async delete(id:
|
|
46
|
+
async delete(id: string): Promise<boolean> {
|
|
46
47
|
|
|
47
48
|
const deletedRole = await this._repository.delete(id);
|
|
48
49
|
return deletedRole;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
async findById(id:
|
|
52
|
+
async findById(id: string): Promise<IRole | null> {
|
|
52
53
|
const role: IRole = await this._repository.findById(id);
|
|
53
54
|
return role
|
|
54
55
|
}
|
|
@@ -63,8 +64,14 @@ class RoleService {
|
|
|
63
64
|
return roles
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
async paginate(
|
|
67
|
-
|
|
67
|
+
async paginate({
|
|
68
|
+
page= 1,
|
|
69
|
+
limit= 5,
|
|
70
|
+
orderBy= '',
|
|
71
|
+
orderDesc= false,
|
|
72
|
+
search= '',
|
|
73
|
+
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<IRole>>{
|
|
74
|
+
const pagination = await this._repository.paginate({page, limit, orderBy, orderDesc, search, filters});
|
|
68
75
|
return pagination;
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {ITenant} from "../interfaces/ITenant";
|
|
2
1
|
import {ITenantRepository} from "../interfaces/ITenantRepository";
|
|
3
|
-
import {
|
|
2
|
+
import {ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
4
3
|
import {tenantSchema} from "../zod/TenantZod.js";
|
|
5
4
|
import {ZodError} from "zod";
|
|
6
|
-
import
|
|
5
|
+
import {ITenantBase, ITenant} from "@drax/identity-share";
|
|
6
|
+
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
|
|
7
7
|
|
|
8
8
|
class TenantService {
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ class TenantService {
|
|
|
14
14
|
console.log("TenantService constructor")
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async create(tenantData:
|
|
17
|
+
async create(tenantData: ITenantBase): Promise<ITenant> {
|
|
18
18
|
try {
|
|
19
19
|
tenantData.name = tenantData?.name?.trim()
|
|
20
20
|
await tenantSchema.parseAsync(tenantData)
|
|
@@ -28,7 +28,7 @@ class TenantService {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async update(id:
|
|
31
|
+
async update(id: string, tenantData: ITenantBase) {
|
|
32
32
|
try {
|
|
33
33
|
tenantData.name = tenantData?.name?.trim()
|
|
34
34
|
await tenantSchema.parseAsync(tenantData)
|
|
@@ -42,13 +42,13 @@ class TenantService {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async delete(id:
|
|
45
|
+
async delete(id: string): Promise<boolean> {
|
|
46
46
|
const currentTenant = await this.findById(id)
|
|
47
47
|
const deletedTenant = await this._repository.delete(id);
|
|
48
48
|
return deletedTenant;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async findById(id:
|
|
51
|
+
async findById(id: string): Promise<ITenant | null> {
|
|
52
52
|
const tenant: ITenant = await this._repository.findById(id);
|
|
53
53
|
return tenant
|
|
54
54
|
}
|
|
@@ -63,8 +63,14 @@ class TenantService {
|
|
|
63
63
|
return tenants
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
async paginate(
|
|
67
|
-
|
|
66
|
+
async paginate({
|
|
67
|
+
page= 1,
|
|
68
|
+
limit= 5,
|
|
69
|
+
orderBy= '',
|
|
70
|
+
orderDesc= false,
|
|
71
|
+
search= '',
|
|
72
|
+
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<ITenant>>{
|
|
73
|
+
const pagination = await this._repository.paginate({page, limit, orderBy, orderDesc, search, filters});
|
|
68
74
|
return pagination;
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {IUser, IUserCreate, IUserUpdate} from "
|
|
1
|
+
import type {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
|
|
2
2
|
import type {IUserRepository} from "../interfaces/IUserRepository";
|
|
3
|
-
import type {IPaginateFilter, IPaginateResult} from "@drax/common-back"
|
|
4
3
|
import {ZodError} from "zod";
|
|
5
4
|
import {ValidationError, ZodErrorToValidationError} from "@drax/common-back";
|
|
6
5
|
import AuthUtils from "../utils/AuthUtils.js";
|
|
7
6
|
import {createUserSchema, editUserSchema,} from "../zod/UserZod.js";
|
|
8
7
|
import BadCredentialsError from "../errors/BadCredentialsError.js";
|
|
8
|
+
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
|
|
9
9
|
|
|
10
10
|
class UserService {
|
|
11
11
|
|
|
@@ -64,6 +64,7 @@ class UserService {
|
|
|
64
64
|
userData.name = userData?.name?.trim()
|
|
65
65
|
userData.username = userData.username.trim()
|
|
66
66
|
userData.password = userData.password.trim()
|
|
67
|
+
userData.tenant = userData.tenant === "" ? null : userData.tenant
|
|
67
68
|
|
|
68
69
|
await createUserSchema.parseAsync(userData)
|
|
69
70
|
|
|
@@ -81,11 +82,12 @@ class UserService {
|
|
|
81
82
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
async update(id:
|
|
85
|
+
async update(id: string, userData: IUserUpdate) {
|
|
85
86
|
try{
|
|
86
87
|
userData.name = userData.name.trim()
|
|
87
88
|
userData.username = userData.username.trim()
|
|
88
89
|
delete userData.password
|
|
90
|
+
userData.tenant = userData.tenant === "" ? null : userData.tenant
|
|
89
91
|
|
|
90
92
|
await editUserSchema.parseAsync(userData)
|
|
91
93
|
|
|
@@ -100,12 +102,12 @@ class UserService {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
async delete(id:
|
|
105
|
+
async delete(id: string): Promise<boolean> {
|
|
104
106
|
const deletedRole: boolean = await this._repository.delete(id);
|
|
105
107
|
return deletedRole;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
async findById(id:
|
|
110
|
+
async findById(id: string): Promise<IUser> {
|
|
109
111
|
const user: IUser = await this._repository.findById(id);
|
|
110
112
|
return user
|
|
111
113
|
}
|
|
@@ -115,9 +117,15 @@ class UserService {
|
|
|
115
117
|
return user
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
async paginate(
|
|
120
|
+
async paginate({
|
|
121
|
+
page= 1,
|
|
122
|
+
limit= 5,
|
|
123
|
+
orderBy= '',
|
|
124
|
+
orderDesc= false,
|
|
125
|
+
search= '',
|
|
126
|
+
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<IUser>>{
|
|
119
127
|
|
|
120
|
-
const pagination = await this._repository.paginate( page, limit, search, filters);
|
|
128
|
+
const pagination = await this._repository.paginate( {page, limit, orderBy, orderDesc, search, filters});
|
|
121
129
|
return pagination;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IRoleBase} from "@drax/identity-share"
|
|
2
2
|
import RoleServiceFactory from "../factory/RoleServiceFactory.js"
|
|
3
3
|
|
|
4
|
-
async function CreateOrUpdateRole(roleData:
|
|
4
|
+
async function CreateOrUpdateRole(roleData: IRoleBase) {
|
|
5
5
|
const roleService = RoleServiceFactory()
|
|
6
6
|
const role = await roleService.findByName(roleData.name)
|
|
7
7
|
if(role){
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import RoleServiceFactory from "../factory/RoleServiceFactory.js"
|
|
2
2
|
import UserServiceFactory from "../factory/UserServiceFactory.js"
|
|
3
|
-
import {IUserCreate} from "
|
|
3
|
+
import {IUserCreate} from "@drax/identity-share";
|
|
4
4
|
|
|
5
5
|
async function CreateUserIfNotExist(userData: IUserCreate) {
|
|
6
6
|
const userService = UserServiceFactory()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import RoleService from "../../src/services/RoleService";
|
|
2
|
-
import {IRole} from "
|
|
2
|
+
import {IRole} from "../../../identity-share/src/interfaces/IRole";
|
|
3
3
|
import RoleMongoRepository from "../../src/repository/mongo/RoleMongoRepository";
|
|
4
4
|
|
|
5
5
|
class RoleMongoInitializer {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import RoleService from "../../src/services/RoleService";
|
|
2
|
-
import {IRole} from "
|
|
2
|
+
import {IRole} from "../../../identity-share/src/interfaces/IRole";
|
|
3
3
|
import RoleSqliteRepository from "../../src/repository/sqlite/RoleSqliteRepository";
|
|
4
4
|
import {UUID} from "crypto";
|
|
5
5
|
|
|
@@ -2,7 +2,7 @@ import {describe,it, before, after} from "node:test"
|
|
|
2
2
|
import {equal} from "assert";
|
|
3
3
|
import RoleMongoRepository from "../../../src/repository/mongo/RoleMongoRepository";
|
|
4
4
|
import MongoInMemory from "../../db/MongoInMemory";
|
|
5
|
-
import {IRole} from "
|
|
5
|
+
import {IRole} from "../../../../identity-share/src/interfaces/IRole";
|
|
6
6
|
import {PaginateResult} from "mongoose";
|
|
7
7
|
import {IPaginateResult} from "@drax/common-back";
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@ import assert, {equal} from "assert";
|
|
|
3
3
|
import UserMongoRepository from "../../../src/repository/mongo/UserMongoRepository";
|
|
4
4
|
import MongoInMemory from "../../db/MongoInMemory";
|
|
5
5
|
import RoleMongoInitializer from "../../initializers/RoleMongoInitializer";
|
|
6
|
-
import {IUser} from "
|
|
6
|
+
import {IUser} from "../../../../identity-share/src/interfaces/IUser";
|
|
7
7
|
import type {IPaginateResult} from "@drax/common-back";
|
|
8
8
|
import {mongoose, ValidationError} from "@drax/common-back";
|
|
9
9
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {describe,it, before, after} from "node:test"
|
|
2
2
|
import {equal} from "assert";
|
|
3
|
-
import {IRole} from "
|
|
3
|
+
import {IRole} from "../../../../identity-share/src/interfaces/IRole";
|
|
4
4
|
import {IPaginateResult} from "@drax/common-back";
|
|
5
5
|
import RoleSqliteRepository from "../../../src/repository/sqlite/RoleSqliteRepository";
|
|
6
6
|
import {UUID} from "crypto";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {before, after, describe, it, test} from "node:test"
|
|
2
2
|
import assert, {equal} from "assert";
|
|
3
3
|
import UserSqliteRepository from "../../../src/repository/sqlite/UserSqliteRepository";
|
|
4
|
-
import {IUser} from "
|
|
5
|
-
import {IRole} from "
|
|
4
|
+
import {IUser} from "../../../../identity-share/src/interfaces/IUser";
|
|
5
|
+
import {IRole} from "../../../../identity-share/src/interfaces/IRole";
|
|
6
6
|
|
|
7
7
|
import {ValidationError} from "@drax/common-back";
|
|
8
8
|
import {UUID} from "crypto";
|
|
@@ -2,7 +2,7 @@ import {describe,it, before, after} from "node:test"
|
|
|
2
2
|
import assert from "assert";
|
|
3
3
|
import RoleService from "../../src/services/RoleService";
|
|
4
4
|
import MongoInMemory from "../db/MongoInMemory";
|
|
5
|
-
import {IRole} from "
|
|
5
|
+
import {IRole} from "../../../identity-share/src/interfaces/IRole";
|
|
6
6
|
import RoleMongoRepository from "../../src/repository/mongo/RoleMongoRepository";
|
|
7
7
|
import {IRoleRepository} from "../../src/interfaces/IRoleRepository";
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ describe("RoleServiceTest", function() {
|
|
|
21
21
|
return
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it("should
|
|
24
|
+
it("should create role", async function() {
|
|
25
25
|
let roleData = (await import("../data-obj/roles/admin-mongo-role")).default
|
|
26
26
|
let roleCreated: IRole = await roleService.create(roleData)
|
|
27
27
|
|
|
@@ -3,7 +3,7 @@ import assert from "assert";
|
|
|
3
3
|
import UserService from "../../src/services/UserService";
|
|
4
4
|
import MongoInMemory from "../db/MongoInMemory";
|
|
5
5
|
import RoleMongoInitializer from "../initializers/RoleMongoInitializer";
|
|
6
|
-
import {IRole} from "
|
|
6
|
+
import {IRole} from "../../../identity-share/src/interfaces/IRole";
|
|
7
7
|
import UserMongoRepository from "../../src/repository/mongo/UserMongoRepository";
|
|
8
8
|
import {IUserRepository} from "../../src/interfaces/IUserRepository";
|
|
9
9
|
import {ValidationError} from "@drax/common-back";
|
|
@@ -28,7 +28,7 @@ describe("UserServiceTest", function () {
|
|
|
28
28
|
return
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
it("should
|
|
31
|
+
it("should create user", async function () {
|
|
32
32
|
const user = {...userAdminData}
|
|
33
33
|
let userCreated = await userService.create(user)
|
|
34
34
|
assert.equal(userCreated.username, userAdminData.username)
|
|
@@ -49,7 +49,7 @@ describe("UserServiceTest", function () {
|
|
|
49
49
|
assert.equal(passwordChangedResult, true)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
it("should fail
|
|
52
|
+
it("should fail create user with short password", async function () {
|
|
53
53
|
let userData = {...userAdminData, password: "123"}
|
|
54
54
|
await assert.rejects(
|
|
55
55
|
async () => {
|