rez_core 1.0.62 → 1.0.64
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/.idea/250218_nodejs_core.iml +12 -0
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/dataSources.xml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/dist/constant/global.constant.d.ts +3 -0
- package/dist/constant/global.constant.js +4 -1
- package/dist/constant/global.constant.js.map +1 -1
- package/dist/module/auth/guards/role.guard.js +3 -3
- package/dist/module/listmaster/controller/list-master.controller.d.ts +1 -1
- package/dist/module/listmaster/controller/list-master.controller.js +3 -4
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.d.ts +4 -2
- package/dist/module/listmaster/service/list-master.service.js +16 -14
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/module/meta/controller/meta.controller.d.ts +7 -0
- package/dist/module/meta/controller/meta.controller.js +47 -0
- package/dist/module/meta/controller/meta.controller.js.map +1 -0
- package/dist/module/meta/dto/entity-table.dto.d.ts +5 -0
- package/dist/module/meta/dto/entity-table.dto.js +8 -0
- package/dist/module/meta/dto/entity-table.dto.js.map +1 -0
- package/dist/module/meta/entity.module.js +2 -1
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/repository/entity-table-column.repository.js +1 -0
- package/dist/module/meta/repository/entity-table-column.repository.js.map +1 -1
- package/dist/module/meta/service/entity-table.service.d.ts +6 -1
- package/dist/module/meta/service/entity-table.service.js +18 -2
- package/dist/module/meta/service/entity-table.service.js.map +1 -1
- package/dist/module/user/entity/role.entity.d.ts +1 -0
- package/dist/module/user/entity/role.entity.js +5 -0
- package/dist/module/user/entity/role.entity.js.map +1 -1
- package/dist/module/user/repository/role.repository.d.ts +2 -35
- package/dist/module/user/repository/role.repository.js +2 -95
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/service/role.service.d.ts +5 -32
- package/dist/module/user/service/role.service.js +71 -24
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/user.module.js +8 -3
- package/dist/module/user/user.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/app.controller.ts +12 -12
- package/src/app.service.ts +8 -8
- package/src/constant/global.constant.ts +5 -0
- package/src/module/auth/guards/jwt.guard.ts +22 -22
- package/src/module/auth/guards/role.guard.ts +68 -68
- package/src/module/auth/services/jwt.service.ts +11 -11
- package/src/module/auth/strategies/local.strategy.ts +13 -13
- package/src/module/dev/dev.module.ts +12 -12
- package/src/module/dev/service/dev.service.ts +7 -7
- package/src/module/enterprise/entity/organization.entity.ts +80 -80
- package/src/module/listmaster/controller/list-master.controller.ts +2 -2
- package/src/module/listmaster/service/list-master.service.ts +18 -15
- package/src/module/meta/controller/meta.controller.ts +22 -0
- package/src/module/meta/dto/entity-list-data.dto.ts +6 -6
- package/src/module/meta/dto/entity-table.dto.ts +6 -0
- package/src/module/meta/entity/preference.entity.ts +65 -65
- package/src/module/meta/entity.module.ts +2 -1
- package/src/module/meta/repository/entity-table-column.repository.ts +1 -0
- package/src/module/meta/repository/preference.repository.ts +20 -20
- package/src/module/meta/service/entity-table.service.ts +43 -3
- package/src/module/module/controller/menu.controller.ts +15 -15
- package/src/module/module/entity/module-access.entity.ts +22 -22
- package/src/module/user/controller/user.controller.ts +28 -28
- package/src/module/user/dto/update-user.dto.ts +4 -4
- package/src/module/user/entity/role.entity.ts +4 -0
- package/src/module/user/entity/user-session.entity.ts +61 -61
- package/src/module/user/repository/role.repository.ts +2 -142
- package/src/module/user/repository/userSession.repository.ts +33 -33
- package/src/module/user/service/role.service.ts +92 -42
- package/src/module/user/user.module.ts +8 -3
- package/src/utils/service/encryptUtil.service.ts +97 -97
- package/src/utils/service/excelUtil.service.ts +15 -15
- package/src/utils/service/reflection-helper.service.ts +53 -53
- package/dist/module/user/controller/role.controller.d.ts +0 -41
- package/dist/module/user/controller/role.controller.js +0 -63
- package/dist/module/user/controller/role.controller.js.map +0 -1
- package/src/module/user/controller/role.controller.ts +0 -55
|
@@ -9,155 +9,15 @@ import { UserData } from '../entity/user.entity';
|
|
|
9
9
|
export class RoleRepository {
|
|
10
10
|
constructor(
|
|
11
11
|
@InjectRepository(Role)
|
|
12
|
-
private readonly roleRepo: Repository<Role
|
|
13
|
-
@InjectRepository(ModuleAccess)
|
|
14
|
-
private readonly moduleAccessRepo: Repository<ModuleAccess>
|
|
12
|
+
private readonly roleRepo: Repository<Role>
|
|
15
13
|
) {}
|
|
16
14
|
|
|
17
15
|
async findByCode(code: string): Promise<Role | null> {
|
|
18
16
|
return this.roleRepo.findOne({ where: { code } });
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
async createRole(
|
|
22
|
-
{
|
|
23
|
-
name,
|
|
24
|
-
description,
|
|
25
|
-
status = 'ACTIVE',
|
|
26
|
-
copyFromRoleId,
|
|
27
|
-
}: {
|
|
28
|
-
name: string;
|
|
29
|
-
description?: string;
|
|
30
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
31
|
-
copyFromRoleId?: number;
|
|
32
|
-
},
|
|
33
|
-
loggedInUser: UserData,
|
|
34
|
-
) {
|
|
35
|
-
if (await this.isRoleNameExists(name)) {
|
|
36
|
-
throw new BadRequestException('Role name already exists.');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const sourceRole = copyFromRoleId
|
|
40
|
-
? await this.roleRepo.findOne({ where: { id: copyFromRoleId } })
|
|
41
|
-
: null;
|
|
42
|
-
|
|
43
|
-
if (copyFromRoleId && !sourceRole) {
|
|
44
|
-
throw new BadRequestException('Source role not found.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const newRole = this.roleRepo.create({
|
|
48
|
-
name,
|
|
49
|
-
description,
|
|
50
|
-
status,
|
|
51
|
-
created_by: loggedInUser.id,
|
|
52
|
-
created_date: new Date(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const savedRole = await this.roleRepo.save(newRole);
|
|
56
|
-
savedRole.code = `ROL${savedRole.id}`;
|
|
57
|
-
await this.roleRepo.save(savedRole);
|
|
58
|
-
|
|
59
|
-
if (sourceRole) {
|
|
60
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
61
|
-
where: { role_code: sourceRole.code },
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
65
|
-
this.moduleAccessRepo.create({
|
|
66
|
-
role_code: savedRole.code,
|
|
67
|
-
module_code: perm.module_code,
|
|
68
|
-
action_type: perm.action_type,
|
|
69
|
-
access_flag: perm.access_flag,
|
|
70
|
-
app_code: perm.app_code,
|
|
71
|
-
}),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
msg: 'Role created successfully',
|
|
80
|
-
role: {
|
|
81
|
-
id: savedRole.id,
|
|
82
|
-
name: savedRole.name,
|
|
83
|
-
status: savedRole.status,
|
|
84
|
-
code: savedRole.code,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async updateRole(
|
|
90
|
-
roleId: number,
|
|
91
|
-
{
|
|
92
|
-
name,
|
|
93
|
-
description,
|
|
94
|
-
status = 'ACTIVE',
|
|
95
|
-
copyFromRoleId,
|
|
96
|
-
}: {
|
|
97
|
-
name: string;
|
|
98
|
-
description?: string;
|
|
99
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
100
|
-
copyFromRoleId?: number;
|
|
101
|
-
},
|
|
102
|
-
loggedInUser: UserData,
|
|
103
|
-
) {
|
|
104
|
-
if (await this.isRoleNameExists(name, roleId)) {
|
|
105
|
-
throw new BadRequestException('Role name already exists.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const role = await this.roleRepo.findOne({ where: { id: roleId } });
|
|
109
|
-
if (!role) {
|
|
110
|
-
throw new BadRequestException('Role not found');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Object.assign(role, {
|
|
114
|
-
name,
|
|
115
|
-
description: description || '',
|
|
116
|
-
status,
|
|
117
|
-
modified_by: loggedInUser.id,
|
|
118
|
-
modified_date: new Date(),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await this.roleRepo.save(role);
|
|
122
|
-
|
|
123
|
-
if (copyFromRoleId) {
|
|
124
|
-
const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
|
|
125
|
-
if (!sourceRole) {
|
|
126
|
-
throw new BadRequestException('Source role not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
130
|
-
|
|
131
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
132
|
-
where: { role_code: sourceRole.code },
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
136
|
-
this.moduleAccessRepo.create({
|
|
137
|
-
role_code: role.code,
|
|
138
|
-
module_code: perm.module_code,
|
|
139
|
-
action_type: perm.action_type,
|
|
140
|
-
access_flag: perm.access_flag,
|
|
141
|
-
app_code: perm.app_code,
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
success: true,
|
|
150
|
-
msg: 'Role updated successfully',
|
|
151
|
-
role: {
|
|
152
|
-
id: role.id,
|
|
153
|
-
name: role.name,
|
|
154
|
-
status: role.status,
|
|
155
|
-
code: role.code,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
19
|
|
|
160
|
-
|
|
20
|
+
public async isRoleNameExists(name: string, excludeRoleId?: number): Promise<boolean> {
|
|
161
21
|
const query = this.roleRepo
|
|
162
22
|
.createQueryBuilder('role')
|
|
163
23
|
.where('role.name = :name', { name });
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Repository } from 'typeorm';
|
|
2
|
-
import { UserSession } from '../entity/user-session.entity';
|
|
3
|
-
import { Injectable } from '@nestjs/common';
|
|
4
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class UserSessionRepository {
|
|
8
|
-
constructor(
|
|
9
|
-
@InjectRepository(UserSession)
|
|
10
|
-
private userSessionRepo: Repository<UserSession>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
14
|
-
return this.userSessionRepo.findOne({ where: { session_key: sessionKey } });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async findActiveSessionByUserId(userId: number): Promise<UserSession | null> {
|
|
18
|
-
return this.userSessionRepo.findOne({
|
|
19
|
-
where: { user_id: userId, is_session_loggedout: 0 },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async saveSession(session: UserSession): Promise<UserSession> {
|
|
24
|
-
return this.userSessionRepo.save(session);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async logoutSession(sessionKey: string): Promise<void> {
|
|
28
|
-
await this.userSessionRepo.update(
|
|
29
|
-
{ session_key: sessionKey },
|
|
30
|
-
{ is_session_loggedout: 1, logout_time: new Date() },
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { UserSession } from '../entity/user-session.entity';
|
|
3
|
+
import { Injectable } from '@nestjs/common';
|
|
4
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class UserSessionRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(UserSession)
|
|
10
|
+
private userSessionRepo: Repository<UserSession>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
14
|
+
return this.userSessionRepo.findOne({ where: { session_key: sessionKey } });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findActiveSessionByUserId(userId: number): Promise<UserSession | null> {
|
|
18
|
+
return this.userSessionRepo.findOne({
|
|
19
|
+
where: { user_id: userId, is_session_loggedout: 0 },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async saveSession(session: UserSession): Promise<UserSession> {
|
|
24
|
+
return this.userSessionRepo.save(session);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async logoutSession(sessionKey: string): Promise<void> {
|
|
28
|
+
await this.userSessionRepo.update(
|
|
29
|
+
{ session_key: sessionKey },
|
|
30
|
+
{ is_session_loggedout: 1, logout_time: new Date() },
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -5,14 +5,18 @@ import { UserData } from '../entity/user.entity';
|
|
|
5
5
|
import { Role } from '../entity/role.entity';
|
|
6
6
|
import { ENTITYTYPE_ROLE } from 'src/constant/global.constant';
|
|
7
7
|
import { RoleRepository } from '../repository/role.repository';
|
|
8
|
-
import { EntityManager } from 'typeorm';
|
|
8
|
+
import { EntityManager, Repository } from 'typeorm';
|
|
9
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
10
|
+
import { ModuleAccess } from '../../module/entity/module-access.entity';
|
|
11
|
+
import { instanceToPlain } from 'class-transformer';
|
|
9
12
|
|
|
10
13
|
@Injectable()
|
|
11
14
|
export class RoleService extends EntityServiceImpl {
|
|
12
15
|
constructor(
|
|
13
16
|
private readonly roleRepository: RoleRepository,
|
|
14
17
|
private readonly entityManager: EntityManager,
|
|
15
|
-
|
|
18
|
+
@InjectRepository(ModuleAccess)
|
|
19
|
+
private readonly moduleAccessRepo: Repository<ModuleAccess>,
|
|
16
20
|
) {
|
|
17
21
|
super();
|
|
18
22
|
}
|
|
@@ -23,46 +27,64 @@ export class RoleService extends EntityServiceImpl {
|
|
|
23
27
|
): Promise<BaseEntity> {
|
|
24
28
|
let role = entityData as Role;
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
if (await this.roleRepository.isRoleNameExists(role.name)) {
|
|
31
|
+
throw new BadRequestException('Role name already exists.');
|
|
32
|
+
}
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const sourceRole = role.copy_from_role_id
|
|
35
|
+
? await this.getEntityData(ENTITYTYPE_ROLE, role.copy_from_role_id)
|
|
36
|
+
: null;
|
|
37
|
+
|
|
38
|
+
if (role.copy_from_role_id && !sourceRole) {
|
|
39
|
+
throw new BadRequestException('Source role not found.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const savedRole = await super.createEntity(role, loggedInUser);
|
|
43
|
+
if (sourceRole) {
|
|
44
|
+
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
45
|
+
where: { role_code: sourceRole.code },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const clonedPermissions = sourcePermissions.map((perm) =>
|
|
49
|
+
this.moduleAccessRepo.create({
|
|
50
|
+
role_code: savedRole.code,
|
|
51
|
+
module_code: perm.module_code,
|
|
52
|
+
action_type: perm.action_type,
|
|
53
|
+
access_flag: perm.access_flag,
|
|
54
|
+
app_code: perm.app_code,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await this.moduleAccessRepo.save(clonedPermissions);
|
|
59
|
+
}
|
|
60
|
+
return savedRole;
|
|
39
61
|
}
|
|
40
62
|
|
|
41
|
-
async
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
47
|
-
copyFromRoleId?: number;
|
|
48
|
-
},
|
|
49
|
-
loggedInUser: UserData,
|
|
50
|
-
) {
|
|
51
|
-
if (!body.name) {
|
|
63
|
+
async updateEntity(
|
|
64
|
+
entityData: BaseEntity,
|
|
65
|
+
loggedInUser: UserData | null,
|
|
66
|
+
): Promise<BaseEntity> {
|
|
67
|
+
if (!entityData.name) {
|
|
52
68
|
throw new BadRequestException('Role name is required');
|
|
53
69
|
}
|
|
70
|
+
const role = entityData as Role;
|
|
54
71
|
|
|
55
|
-
if (
|
|
72
|
+
if (entityData.status === 'INACTIVE') {
|
|
56
73
|
//get role by id
|
|
57
|
-
const
|
|
74
|
+
const existingRole = await this.getEntityData(
|
|
58
75
|
ENTITYTYPE_ROLE,
|
|
59
|
-
id,
|
|
76
|
+
entityData.id,
|
|
60
77
|
);
|
|
61
78
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
if (!existingRole) {
|
|
80
|
+
throw new BadRequestException('Role not found');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const associatedUsers = await this.entityManager.query(`SELECT map.*
|
|
84
|
+
FROM cr_user_role_mapping map
|
|
85
|
+
JOIN cr_user usr ON map.user_id = usr.id
|
|
86
|
+
WHERE usr.status = 'ACTIVE'
|
|
87
|
+
and map.role_id = ${existingRole?.id}`);
|
|
66
88
|
|
|
67
89
|
if (associatedUsers.length > 0) {
|
|
68
90
|
throw new BadRequestException(
|
|
@@ -70,20 +92,48 @@ export class RoleService extends EntityServiceImpl {
|
|
|
70
92
|
);
|
|
71
93
|
}
|
|
72
94
|
|
|
73
|
-
if (!entityData) {
|
|
74
|
-
throw new BadRequestException('Role not found');
|
|
75
|
-
}
|
|
76
|
-
const role = entityData as Role;
|
|
77
95
|
if (role.is_system === 1) {
|
|
78
96
|
throw new BadRequestException('Cannot deactivate system role');
|
|
79
97
|
}
|
|
80
98
|
}
|
|
81
99
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
if (
|
|
101
|
+
await this.roleRepository.isRoleNameExists(entityData.name, entityData.id)
|
|
102
|
+
) {
|
|
103
|
+
throw new BadRequestException('Role name already exists.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const {copy_from_role_id, ...persistableData} = role;
|
|
107
|
+
const updatedRole = await super.updateEntity(persistableData, loggedInUser);
|
|
108
|
+
|
|
109
|
+
if (role.copy_from_role_id) {
|
|
110
|
+
const sourceRole = await this.getEntityData(
|
|
111
|
+
ENTITYTYPE_ROLE,
|
|
112
|
+
role.copy_from_role_id,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (!sourceRole) {
|
|
116
|
+
throw new BadRequestException('Source role not found');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
120
|
+
|
|
121
|
+
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
122
|
+
where: { role_code: sourceRole.code },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const clonedPermissions = sourcePermissions.map((perm) =>
|
|
126
|
+
this.moduleAccessRepo.create({
|
|
127
|
+
role_code: role.code,
|
|
128
|
+
module_code: perm.module_code,
|
|
129
|
+
action_type: perm.action_type,
|
|
130
|
+
access_flag: perm.access_flag,
|
|
131
|
+
app_code: perm.app_code,
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
await this.moduleAccessRepo.save(clonedPermissions);
|
|
136
|
+
}
|
|
137
|
+
return updatedRole;
|
|
88
138
|
}
|
|
89
139
|
}
|
|
@@ -20,11 +20,16 @@ import { UserRoleMappingRepository } from './repository/user-role-mapping.reposi
|
|
|
20
20
|
import { UserRoleMappingService } from './service/user-role-mapping.service';
|
|
21
21
|
import { RoleRepository } from './repository/role.repository';
|
|
22
22
|
import { ModuleAccess } from '../module/entity/module-access.entity';
|
|
23
|
-
import { RoleController } from './controller/role.controller';
|
|
24
23
|
|
|
25
24
|
@Module({
|
|
26
25
|
imports: [
|
|
27
|
-
TypeOrmModule.forFeature([
|
|
26
|
+
TypeOrmModule.forFeature([
|
|
27
|
+
UserData,
|
|
28
|
+
UserSession,
|
|
29
|
+
Role,
|
|
30
|
+
UserRoleMapping,
|
|
31
|
+
ModuleAccess,
|
|
32
|
+
]),
|
|
28
33
|
EntityModule,
|
|
29
34
|
UtilsModule,
|
|
30
35
|
AuthModule,
|
|
@@ -49,6 +54,6 @@ import { RoleController } from './controller/role.controller';
|
|
|
49
54
|
RoleRepository,
|
|
50
55
|
LoginService,
|
|
51
56
|
],
|
|
52
|
-
controllers: [LoginController, UserController
|
|
57
|
+
controllers: [LoginController, UserController],
|
|
53
58
|
})
|
|
54
59
|
export class UserModule {}
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
2
|
-
import * as crypto from 'crypto';
|
|
3
|
-
|
|
4
|
-
const CryptoJS = require('crypto-js');
|
|
5
|
-
const encryptionType = 'aes-256-cbc';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class EncryptUtilService {
|
|
9
|
-
constructor() {}
|
|
10
|
-
|
|
11
|
-
static encryptGCM(data: any, Datakey: string, Dataiv: string) {
|
|
12
|
-
try {
|
|
13
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
14
|
-
let encrypted = Buffer.concat([
|
|
15
|
-
cipher.update(data, 'utf8'),
|
|
16
|
-
cipher.final(),
|
|
17
|
-
]);
|
|
18
|
-
const tag = cipher.getAuthTag();
|
|
19
|
-
return Buffer.concat([encrypted, tag]).toString('base64');
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static decryptGCM(data: any, Datakey: any, Dataiv: any) {
|
|
26
|
-
try {
|
|
27
|
-
data = Buffer.from(data, 'base64');
|
|
28
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
29
|
-
const tag = data.slice(data.length - 16);
|
|
30
|
-
decipher.setAuthTag(tag);
|
|
31
|
-
data = data.slice(0, data.length - 16);
|
|
32
|
-
let decrypted = decipher.update(data, 'utf8') + decipher.final('utf8');
|
|
33
|
-
return decrypted;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static encryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
40
|
-
let encryptedRequest;
|
|
41
|
-
try {
|
|
42
|
-
let cipher = CryptoJS.AES.encrypt(data, Datakey, {
|
|
43
|
-
iv: Dataiv,
|
|
44
|
-
mode: CryptoJS.mode.CBC,
|
|
45
|
-
});
|
|
46
|
-
encryptedRequest = cipher.toString();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.log(error);
|
|
49
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
50
|
-
}
|
|
51
|
-
return encryptedRequest;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static decryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
55
|
-
let decryptRequest;
|
|
56
|
-
try {
|
|
57
|
-
let cipher = CryptoJS.AES.decrypt(data, Datakey, {
|
|
58
|
-
iv: Dataiv,
|
|
59
|
-
mode: CryptoJS.mode.CBC,
|
|
60
|
-
});
|
|
61
|
-
decryptRequest = cipher.toString(CryptoJS.enc.Utf8);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
64
|
-
}
|
|
65
|
-
return decryptRequest;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static encryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
69
|
-
try {
|
|
70
|
-
switch (type) {
|
|
71
|
-
case 'GCM':
|
|
72
|
-
return this.encryptGCM(data, Datakey, Dataiv);
|
|
73
|
-
case 'CBC':
|
|
74
|
-
return this.encryptCBC(data, Datakey, Dataiv);
|
|
75
|
-
default:
|
|
76
|
-
return this.encryptCBC(data, Datakey, Dataiv);
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static decryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
84
|
-
try {
|
|
85
|
-
switch (type) {
|
|
86
|
-
case 'GCM':
|
|
87
|
-
return this.decryptGCM(data, Datakey, Dataiv);
|
|
88
|
-
case 'CBC':
|
|
89
|
-
return this.decryptCBC(data, Datakey, Dataiv);
|
|
90
|
-
default:
|
|
91
|
-
return this.decryptCBC(data, Datakey, Dataiv);
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
1
|
+
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
|
|
4
|
+
const CryptoJS = require('crypto-js');
|
|
5
|
+
const encryptionType = 'aes-256-cbc';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class EncryptUtilService {
|
|
9
|
+
constructor() {}
|
|
10
|
+
|
|
11
|
+
static encryptGCM(data: any, Datakey: string, Dataiv: string) {
|
|
12
|
+
try {
|
|
13
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
14
|
+
let encrypted = Buffer.concat([
|
|
15
|
+
cipher.update(data, 'utf8'),
|
|
16
|
+
cipher.final(),
|
|
17
|
+
]);
|
|
18
|
+
const tag = cipher.getAuthTag();
|
|
19
|
+
return Buffer.concat([encrypted, tag]).toString('base64');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static decryptGCM(data: any, Datakey: any, Dataiv: any) {
|
|
26
|
+
try {
|
|
27
|
+
data = Buffer.from(data, 'base64');
|
|
28
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
29
|
+
const tag = data.slice(data.length - 16);
|
|
30
|
+
decipher.setAuthTag(tag);
|
|
31
|
+
data = data.slice(0, data.length - 16);
|
|
32
|
+
let decrypted = decipher.update(data, 'utf8') + decipher.final('utf8');
|
|
33
|
+
return decrypted;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static encryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
40
|
+
let encryptedRequest;
|
|
41
|
+
try {
|
|
42
|
+
let cipher = CryptoJS.AES.encrypt(data, Datakey, {
|
|
43
|
+
iv: Dataiv,
|
|
44
|
+
mode: CryptoJS.mode.CBC,
|
|
45
|
+
});
|
|
46
|
+
encryptedRequest = cipher.toString();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.log(error);
|
|
49
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
50
|
+
}
|
|
51
|
+
return encryptedRequest;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static decryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
55
|
+
let decryptRequest;
|
|
56
|
+
try {
|
|
57
|
+
let cipher = CryptoJS.AES.decrypt(data, Datakey, {
|
|
58
|
+
iv: Dataiv,
|
|
59
|
+
mode: CryptoJS.mode.CBC,
|
|
60
|
+
});
|
|
61
|
+
decryptRequest = cipher.toString(CryptoJS.enc.Utf8);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
64
|
+
}
|
|
65
|
+
return decryptRequest;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static encryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
69
|
+
try {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case 'GCM':
|
|
72
|
+
return this.encryptGCM(data, Datakey, Dataiv);
|
|
73
|
+
case 'CBC':
|
|
74
|
+
return this.encryptCBC(data, Datakey, Dataiv);
|
|
75
|
+
default:
|
|
76
|
+
return this.encryptCBC(data, Datakey, Dataiv);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static decryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
84
|
+
try {
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 'GCM':
|
|
87
|
+
return this.decryptGCM(data, Datakey, Dataiv);
|
|
88
|
+
case 'CBC':
|
|
89
|
+
return this.decryptCBC(data, Datakey, Dataiv);
|
|
90
|
+
default:
|
|
91
|
+
return this.decryptCBC(data, Datakey, Dataiv);
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as xlsx from 'xlsx';
|
|
2
|
-
|
|
3
|
-
export class ExcelUtil {
|
|
4
|
-
static readExcel(fileBuffer: Buffer): Record<string, any[]> {
|
|
5
|
-
const workbook = xlsx.read(fileBuffer, { type: 'buffer' });
|
|
6
|
-
const data: Record<string, any[]> = {};
|
|
7
|
-
|
|
8
|
-
workbook.SheetNames.forEach((sheetName) => {
|
|
9
|
-
const sheet = workbook.Sheets[sheetName];
|
|
10
|
-
data[sheetName] = xlsx.utils.sheet_to_json(sheet);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import * as xlsx from 'xlsx';
|
|
2
|
+
|
|
3
|
+
export class ExcelUtil {
|
|
4
|
+
static readExcel(fileBuffer: Buffer): Record<string, any[]> {
|
|
5
|
+
const workbook = xlsx.read(fileBuffer, { type: 'buffer' });
|
|
6
|
+
const data: Record<string, any[]> = {};
|
|
7
|
+
|
|
8
|
+
workbook.SheetNames.forEach((sheetName) => {
|
|
9
|
+
const sheet = workbook.Sheets[sheetName];
|
|
10
|
+
data[sheetName] = xlsx.utils.sheet_to_json(sheet);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
}
|