rez_core 1.0.62 → 1.0.63
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/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/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/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/dto/entity-list-data.dto.ts +6 -6
- package/src/module/meta/entity/preference.entity.ts +65 -65
- package/src/module/meta/repository/preference.repository.ts +20 -20
- 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
|
@@ -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
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
import { DataSource, Repository } from 'typeorm';
|
|
4
|
-
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class ReflectionHelper {
|
|
8
|
-
constructor(
|
|
9
|
-
private moduleRef: ModuleRef,
|
|
10
|
-
private dataSource: DataSource,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
getRepoService(entityName: string): Repository<any> | null {
|
|
14
|
-
const entityMetadata: any = this.dataSource.entityMetadatas.find(
|
|
15
|
-
(meta) =>
|
|
16
|
-
meta.name === entityName ||
|
|
17
|
-
(meta.target && (meta.target as any).name === entityName),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (!entityMetadata) {
|
|
21
|
-
console.error(`Entity "${entityName}" not found in TypeORM metadata`);
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
return this.moduleRef.get<Repository<any>>(
|
|
27
|
-
getRepositoryToken(entityMetadata.target),
|
|
28
|
-
{ strict: false },
|
|
29
|
-
);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error(`Repository for "${entityName}" not found:`, error.message);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getBean<T>(beanName: string): Promise<T | null> {
|
|
37
|
-
try {
|
|
38
|
-
const provider = this.moduleRef.get<T>(beanName as any, {
|
|
39
|
-
strict: false,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (!provider) {
|
|
43
|
-
console.error(`Bean "${beanName}" not found in moduleRef.`);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return provider;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error(`Bean "${beanName}" not found:`, error.message);
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
import { DataSource, Repository } from 'typeorm';
|
|
4
|
+
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ReflectionHelper {
|
|
8
|
+
constructor(
|
|
9
|
+
private moduleRef: ModuleRef,
|
|
10
|
+
private dataSource: DataSource,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getRepoService(entityName: string): Repository<any> | null {
|
|
14
|
+
const entityMetadata: any = this.dataSource.entityMetadatas.find(
|
|
15
|
+
(meta) =>
|
|
16
|
+
meta.name === entityName ||
|
|
17
|
+
(meta.target && (meta.target as any).name === entityName),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (!entityMetadata) {
|
|
21
|
+
console.error(`Entity "${entityName}" not found in TypeORM metadata`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
return this.moduleRef.get<Repository<any>>(
|
|
27
|
+
getRepositoryToken(entityMetadata.target),
|
|
28
|
+
{ strict: false },
|
|
29
|
+
);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(`Repository for "${entityName}" not found:`, error.message);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getBean<T>(beanName: string): Promise<T | null> {
|
|
37
|
+
try {
|
|
38
|
+
const provider = this.moduleRef.get<T>(beanName as any, {
|
|
39
|
+
strict: false,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!provider) {
|
|
43
|
+
console.error(`Bean "${beanName}" not found in moduleRef.`);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return provider;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`Bean "${beanName}" not found:`, error.message);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { UserService } from '../service/user.service';
|
|
2
|
-
import { RoleService } from '../service/role.service';
|
|
3
|
-
export declare class RoleController {
|
|
4
|
-
private readonly userService;
|
|
5
|
-
private readonly roleService;
|
|
6
|
-
constructor(userService: UserService, roleService: RoleService);
|
|
7
|
-
createRole(body: {
|
|
8
|
-
name: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
11
|
-
copyFromRoleId?: number;
|
|
12
|
-
}, request: Request & {
|
|
13
|
-
user: any;
|
|
14
|
-
}): Promise<{
|
|
15
|
-
success: boolean;
|
|
16
|
-
msg: string;
|
|
17
|
-
role: {
|
|
18
|
-
id: number;
|
|
19
|
-
name: string;
|
|
20
|
-
status: string;
|
|
21
|
-
code: string;
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
24
|
-
updateRole(id: number, body: {
|
|
25
|
-
name?: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
28
|
-
copyFromRoleId?: number;
|
|
29
|
-
}, req: Request & {
|
|
30
|
-
user: any;
|
|
31
|
-
}): Promise<{
|
|
32
|
-
success: boolean;
|
|
33
|
-
msg: string;
|
|
34
|
-
role: {
|
|
35
|
-
id: number;
|
|
36
|
-
name: string;
|
|
37
|
-
status: string;
|
|
38
|
-
code: string;
|
|
39
|
-
};
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.RoleController = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const user_service_1 = require("../service/user.service");
|
|
18
|
-
const global_constant_1 = require("../../../constant/global.constant");
|
|
19
|
-
const role_service_1 = require("../service/role.service");
|
|
20
|
-
const jwt_guard_1 = require("../../auth/guards/jwt.guard");
|
|
21
|
-
let RoleController = class RoleController {
|
|
22
|
-
constructor(userService, roleService) {
|
|
23
|
-
this.userService = userService;
|
|
24
|
-
this.roleService = roleService;
|
|
25
|
-
}
|
|
26
|
-
async createRole(body, request) {
|
|
27
|
-
let requestedUser = request.user;
|
|
28
|
-
let loggedInUser = await this.userService.getEntityData(global_constant_1.ENTITYTYPE_USER, requestedUser.id);
|
|
29
|
-
return this.roleService.createRole(body, loggedInUser);
|
|
30
|
-
}
|
|
31
|
-
async updateRole(id, body, req) {
|
|
32
|
-
let requestedUser = req.user;
|
|
33
|
-
let loggedInUser = await this.userService.getEntityData(global_constant_1.ENTITYTYPE_USER, requestedUser.id);
|
|
34
|
-
return this.roleService.updateRole(id, body, loggedInUser);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
exports.RoleController = RoleController;
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, common_1.Post)('create'),
|
|
40
|
-
__param(0, (0, common_1.Body)()),
|
|
41
|
-
__param(1, (0, common_1.Req)()),
|
|
42
|
-
__metadata("design:type", Function),
|
|
43
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
44
|
-
__metadata("design:returntype", Promise)
|
|
45
|
-
], RoleController.prototype, "createRole", null);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, common_1.Post)('update/:id'),
|
|
48
|
-
__param(0, (0, common_1.Param)('id')),
|
|
49
|
-
__param(1, (0, common_1.Body)()),
|
|
50
|
-
__param(2, (0, common_1.Req)()),
|
|
51
|
-
__metadata("design:type", Function),
|
|
52
|
-
__metadata("design:paramtypes", [Number, Object, Object]),
|
|
53
|
-
__metadata("design:returntype", Promise)
|
|
54
|
-
], RoleController.prototype, "updateRole", null);
|
|
55
|
-
exports.RoleController = RoleController = __decorate([
|
|
56
|
-
(0, common_1.Controller)('role'),
|
|
57
|
-
(0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
|
|
58
|
-
__param(0, (0, common_1.Inject)('UserService')),
|
|
59
|
-
__param(1, (0, common_1.Inject)('RoleService')),
|
|
60
|
-
__metadata("design:paramtypes", [user_service_1.UserService,
|
|
61
|
-
role_service_1.RoleService])
|
|
62
|
-
], RoleController);
|
|
63
|
-
//# sourceMappingURL=role.controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role.controller.js","sourceRoot":"","sources":["../../../../src/module/user/controller/role.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAuF;AACvF,0DAAsD;AACtD,uEAA+D;AAC/D,0DAAsD;AAItD,2DAAgE;AAGzD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAC0C,WAAwB,EACxB,WAAwB;QADxB,gBAAW,GAAX,WAAW,CAAa;QACxB,gBAAW,GAAX,WAAW,CAAa;IAC/D,CAAC;IAGE,AAAN,KAAK,CAAC,UAAU,CAEd,IAKC,EACM,OAAgC;QAEvC,IAAI,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;QACjC,IAAI,YAAY,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CACrD,iCAAe,EACf,aAAa,CAAC,EAAE,CACjB,CAAC;QACF,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,YAAwB,CAAC,CAAC;IACrE,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CACD,EAAU,EAEvB,IAKC,EACM,GAA4B;QAEnC,IAAI,aAAa,GAAG,GAAG,CAAC,IAAI,CAAC;QAC7B,IAAI,YAAY,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CACrD,iCAAe,EACf,aAAa,CAAC,EAAE,CACjB,CAAC;QACF,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,YAAwB,CAAC,CAAC;IACzE,CAAC;CACF,CAAA;AA5CY,wCAAc;AAOnB;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IAEZ,WAAA,IAAA,aAAI,GAAE,CAAA;IAON,WAAA,IAAA,YAAG,GAAE,CAAA;;;;gDAQP;AAGK;IADL,IAAA,aAAI,EAAC,YAAY,CAAC;IAEhB,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,aAAI,GAAE,CAAA;IAON,WAAA,IAAA,YAAG,GAAE,CAAA;;;;gDAQP;yBA3CU,cAAc;IAF1B,IAAA,mBAAU,EAAC,MAAM,CAAC;IAClB,IAAA,kBAAS,EAAC,wBAAY,CAAC;IAGnB,WAAA,IAAA,eAAM,EAAC,aAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,aAAa,CAAC,CAAA;qCAD+B,0BAAW;QACX,0BAAW;GAHvD,cAAc,CA4C1B"}
|