rez_core 1.0.57 → 1.0.59
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/module/auth/guards/role.guard.js +3 -3
- package/dist/module/module/controller/module-access.controller.d.ts +1 -1
- package/dist/module/module/entity/module-action.entity.d.ts +0 -1
- package/dist/module/module/entity/module-action.entity.js +2 -5
- package/dist/module/module/entity/module-action.entity.js.map +1 -1
- package/dist/module/module/module.module.js +1 -1
- package/dist/module/module/module.module.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +11 -5
- package/dist/module/module/repository/module-access.repository.js +67 -96
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +1 -1
- package/dist/resources/dev.properties.yaml +21 -0
- package/dist/resources/uat.properties.yaml +15 -0
- 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/enterprise.entity.ts +37 -37
- package/src/module/enterprise/entity/organization.entity.ts +80 -80
- 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/module/entity/module-action.entity.ts +17 -19
- package/src/module/module/module.module.ts +1 -1
- package/src/module/module/repository/module-access.repository.ts +89 -115
- 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/user-session.entity.ts +61 -61
- package/src/module/user/repository/userSession.repository.ts +33 -33
- 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/.idea/250218_nodejs_core.iml +0 -12
- package/.idea/codeStyles/Project.xml +0 -59
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/dataSources.xml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -6
- package/.idea/vcs.xml +0 -6
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { BaseEntity } from './base-entity.entity';
|
|
2
|
-
import { Column, Entity } from 'typeorm';
|
|
3
|
-
import { ENTITYTYPE_PREFERENCEMASTER } from '../../../constant/global.constant';
|
|
4
|
-
|
|
5
|
-
@Entity({ name: 'cr_preference_master' })
|
|
6
|
-
export class PreferenceMaster extends BaseEntity {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
this.entity_type = ENTITYTYPE_PREFERENCEMASTER;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@Column({ name: 'appcode', type: 'varchar', length: 200, nullable: true })
|
|
13
|
-
appCode: string;
|
|
14
|
-
|
|
15
|
-
@Column({
|
|
16
|
-
name: 'display_name',
|
|
17
|
-
type: 'varchar',
|
|
18
|
-
length: 200,
|
|
19
|
-
nullable: true,
|
|
20
|
-
})
|
|
21
|
-
display_name: string;
|
|
22
|
-
|
|
23
|
-
@Column({
|
|
24
|
-
name: 'preference_key',
|
|
25
|
-
type: 'varchar',
|
|
26
|
-
length: 200,
|
|
27
|
-
nullable: true,
|
|
28
|
-
})
|
|
29
|
-
preference_key: string;
|
|
30
|
-
|
|
31
|
-
@Column({
|
|
32
|
-
name: 'preference_value',
|
|
33
|
-
type: 'varchar',
|
|
34
|
-
length: 200,
|
|
35
|
-
nullable: true,
|
|
36
|
-
})
|
|
37
|
-
preference_value: string;
|
|
38
|
-
|
|
39
|
-
@Column({
|
|
40
|
-
name: 'description',
|
|
41
|
-
type: 'varchar',
|
|
42
|
-
length: 2000,
|
|
43
|
-
nullable: true,
|
|
44
|
-
})
|
|
45
|
-
description: string;
|
|
46
|
-
|
|
47
|
-
@Column({ name: 'reflect_on', type: 'varchar', length: 200, nullable: true })
|
|
48
|
-
reflect_on: string;
|
|
49
|
-
|
|
50
|
-
@Column({
|
|
51
|
-
name: 'default_value',
|
|
52
|
-
type: 'varchar',
|
|
53
|
-
length: 200,
|
|
54
|
-
nullable: true,
|
|
55
|
-
})
|
|
56
|
-
default_value: string;
|
|
57
|
-
|
|
58
|
-
@Column({
|
|
59
|
-
name: 'possible_values',
|
|
60
|
-
type: 'varchar',
|
|
61
|
-
length: 200,
|
|
62
|
-
nullable: true,
|
|
63
|
-
})
|
|
64
|
-
possible_values: string;
|
|
65
|
-
}
|
|
1
|
+
import { BaseEntity } from './base-entity.entity';
|
|
2
|
+
import { Column, Entity } from 'typeorm';
|
|
3
|
+
import { ENTITYTYPE_PREFERENCEMASTER } from '../../../constant/global.constant';
|
|
4
|
+
|
|
5
|
+
@Entity({ name: 'cr_preference_master' })
|
|
6
|
+
export class PreferenceMaster extends BaseEntity {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.entity_type = ENTITYTYPE_PREFERENCEMASTER;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Column({ name: 'appcode', type: 'varchar', length: 200, nullable: true })
|
|
13
|
+
appCode: string;
|
|
14
|
+
|
|
15
|
+
@Column({
|
|
16
|
+
name: 'display_name',
|
|
17
|
+
type: 'varchar',
|
|
18
|
+
length: 200,
|
|
19
|
+
nullable: true,
|
|
20
|
+
})
|
|
21
|
+
display_name: string;
|
|
22
|
+
|
|
23
|
+
@Column({
|
|
24
|
+
name: 'preference_key',
|
|
25
|
+
type: 'varchar',
|
|
26
|
+
length: 200,
|
|
27
|
+
nullable: true,
|
|
28
|
+
})
|
|
29
|
+
preference_key: string;
|
|
30
|
+
|
|
31
|
+
@Column({
|
|
32
|
+
name: 'preference_value',
|
|
33
|
+
type: 'varchar',
|
|
34
|
+
length: 200,
|
|
35
|
+
nullable: true,
|
|
36
|
+
})
|
|
37
|
+
preference_value: string;
|
|
38
|
+
|
|
39
|
+
@Column({
|
|
40
|
+
name: 'description',
|
|
41
|
+
type: 'varchar',
|
|
42
|
+
length: 2000,
|
|
43
|
+
nullable: true,
|
|
44
|
+
})
|
|
45
|
+
description: string;
|
|
46
|
+
|
|
47
|
+
@Column({ name: 'reflect_on', type: 'varchar', length: 200, nullable: true })
|
|
48
|
+
reflect_on: string;
|
|
49
|
+
|
|
50
|
+
@Column({
|
|
51
|
+
name: 'default_value',
|
|
52
|
+
type: 'varchar',
|
|
53
|
+
length: 200,
|
|
54
|
+
nullable: true,
|
|
55
|
+
})
|
|
56
|
+
default_value: string;
|
|
57
|
+
|
|
58
|
+
@Column({
|
|
59
|
+
name: 'possible_values',
|
|
60
|
+
type: 'varchar',
|
|
61
|
+
length: 200,
|
|
62
|
+
nullable: true,
|
|
63
|
+
})
|
|
64
|
+
possible_values: string;
|
|
65
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { PreferenceMaster } from '../entity/preference.entity';
|
|
4
|
-
import { Repository } from 'typeorm';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class PreferenceRepository {
|
|
8
|
-
constructor(
|
|
9
|
-
@InjectRepository(PreferenceMaster)
|
|
10
|
-
private readonly preferenceRepository: Repository<PreferenceMaster>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findByPreferenceKey(
|
|
14
|
-
preferenceKey: string,
|
|
15
|
-
): Promise<PreferenceMaster | null> {
|
|
16
|
-
return await this.preferenceRepository.findOne({
|
|
17
|
-
where: { preference_key: preferenceKey },
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { PreferenceMaster } from '../entity/preference.entity';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class PreferenceRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(PreferenceMaster)
|
|
10
|
+
private readonly preferenceRepository: Repository<PreferenceMaster>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findByPreferenceKey(
|
|
14
|
+
preferenceKey: string,
|
|
15
|
+
): Promise<PreferenceMaster | null> {
|
|
16
|
+
return await this.preferenceRepository.findOne({
|
|
17
|
+
where: { preference_key: preferenceKey },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Controller, Get, Request, UseGuards } from '@nestjs/common';
|
|
2
|
-
import { MenuService } from '../service/menu.service';
|
|
3
|
-
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
4
|
-
|
|
5
|
-
@Controller('menu')
|
|
6
|
-
export class MenuController {
|
|
7
|
-
constructor(private readonly menuService: MenuService) {}
|
|
8
|
-
|
|
9
|
-
@UseGuards(JwtAuthGuard)
|
|
10
|
-
@Get()
|
|
11
|
-
async getMenu(@Request() req) {
|
|
12
|
-
const userId = req.user.userId;
|
|
13
|
-
return this.menuService.getUserMenu(userId);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import { Controller, Get, Request, UseGuards } from '@nestjs/common';
|
|
2
|
+
import { MenuService } from '../service/menu.service';
|
|
3
|
+
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
4
|
+
|
|
5
|
+
@Controller('menu')
|
|
6
|
+
export class MenuController {
|
|
7
|
+
constructor(private readonly menuService: MenuService) {}
|
|
8
|
+
|
|
9
|
+
@UseGuards(JwtAuthGuard)
|
|
10
|
+
@Get()
|
|
11
|
+
async getMenu(@Request() req) {
|
|
12
|
+
const userId = req.user.userId;
|
|
13
|
+
return this.menuService.getUserMenu(userId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
-
|
|
3
|
-
@Entity({ name: 'cr_module_access' })
|
|
4
|
-
export class ModuleAccess {
|
|
5
|
-
@PrimaryGeneratedColumn()
|
|
6
|
-
id: number;
|
|
7
|
-
|
|
8
|
-
@Column({type: 'varchar', length: 100, nullable: true})
|
|
9
|
-
module_code: string;
|
|
10
|
-
|
|
11
|
-
@Column({type: 'varchar', length: 100, nullable: true })
|
|
12
|
-
role_code: string;
|
|
13
|
-
|
|
14
|
-
@Column({type: 'int', nullable: true })
|
|
15
|
-
access_flag: number;
|
|
16
|
-
|
|
17
|
-
@Column({type: 'varchar', length: 100, nullable: true })
|
|
18
|
-
action_type: string;
|
|
19
|
-
|
|
20
|
-
@Column({type: 'varchar', length: 100, nullable: true})
|
|
21
|
-
app_code: string;
|
|
22
|
-
}
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: 'cr_module_access' })
|
|
4
|
+
export class ModuleAccess {
|
|
5
|
+
@PrimaryGeneratedColumn()
|
|
6
|
+
id: number;
|
|
7
|
+
|
|
8
|
+
@Column({type: 'varchar', length: 100, nullable: true})
|
|
9
|
+
module_code: string;
|
|
10
|
+
|
|
11
|
+
@Column({type: 'varchar', length: 100, nullable: true })
|
|
12
|
+
role_code: string;
|
|
13
|
+
|
|
14
|
+
@Column({type: 'int', nullable: true })
|
|
15
|
+
access_flag: number;
|
|
16
|
+
|
|
17
|
+
@Column({type: 'varchar', length: 100, nullable: true })
|
|
18
|
+
action_type: string;
|
|
19
|
+
|
|
20
|
+
@Column({type: 'varchar', length: 100, nullable: true})
|
|
21
|
+
app_code: string;
|
|
22
|
+
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
-
|
|
3
|
-
@Entity({ name: '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
action_type: string;
|
|
19
|
-
}
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: 'cr_module_action' }) // <- new table name
|
|
4
|
+
@Unique(['module_code', 'action_type']) // enforce uniqueness per module + action
|
|
5
|
+
export class ModuleAction {
|
|
6
|
+
@PrimaryGeneratedColumn()
|
|
7
|
+
id: number;
|
|
8
|
+
|
|
9
|
+
@Column({ type: 'varchar', length: 100, nullable: true })
|
|
10
|
+
module_code: string;
|
|
11
|
+
|
|
12
|
+
@Column({ type: 'varchar', length: 100, nullable: true })
|
|
13
|
+
action_name: string;
|
|
14
|
+
|
|
15
|
+
@Column({ type: 'varchar', length: 50, nullable: true })
|
|
16
|
+
action_type: string;
|
|
17
|
+
}
|
|
@@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
|
|
|
2
2
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
3
|
import { ModuleData } from './entity/module.entity';
|
|
4
4
|
import { UtilsModule } from '../../utils/utils.module';
|
|
5
|
-
import { ModuleAccess } from './entity/module-access.entity';
|
|
6
5
|
import { ModuleAction } from './entity/module-action.entity';
|
|
7
6
|
import { ModuleAccessService } from './service/module-access.service';
|
|
8
7
|
import { MenuController } from './controller/menu.controller';
|
|
@@ -14,6 +13,7 @@ import { ModuleAccessController } from './controller/module-access.controller';
|
|
|
14
13
|
import { UserRoleMapping } from '../user/entity/user-role-mapping.entity';
|
|
15
14
|
import { UserModule } from '../user/user.module';
|
|
16
15
|
import { Role } from '../user/entity/role.entity';
|
|
16
|
+
import { ModuleAccess } from './entity/module-access.entity';
|
|
17
17
|
|
|
18
18
|
@Module({
|
|
19
19
|
imports: [
|
|
@@ -24,41 +24,34 @@ export class ModuleAccessRepository {
|
|
|
24
24
|
|
|
25
25
|
async getRoles() {
|
|
26
26
|
const roles = await this.roleRepo.find();
|
|
27
|
-
return roles.map(
|
|
27
|
+
return roles.map(role => ({
|
|
28
28
|
label: role.name,
|
|
29
29
|
value: role.id,
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async getModules() {
|
|
34
|
-
const modules = await this.moduleRepo.find({
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
return modules.map((mod) => ({
|
|
34
|
+
const modules = await this.moduleRepo.find({ where: { module_level: 'MAINMOD' } });
|
|
35
|
+
return modules.map(mod => ({
|
|
38
36
|
label: mod.name,
|
|
39
37
|
value: mod.id,
|
|
40
38
|
}));
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
async getAccessListing(roleIds: number[]) {
|
|
44
|
-
// Fetch roles using role IDs
|
|
45
42
|
const roles = await this.roleRepo.find({ where: { id: In(roleIds) } });
|
|
43
|
+
const roleCodes = roles.map(role => role.code);
|
|
46
44
|
|
|
47
|
-
// Extract role codes from roles
|
|
48
|
-
const roleCodes = roles.map((role) => role.code);
|
|
49
|
-
|
|
50
|
-
// Fetch module access using role codes
|
|
51
45
|
const moduleAccesses = await this.moduleAccessRepo.find({
|
|
52
46
|
where: { role_code: In(roleCodes) },
|
|
53
47
|
});
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
return roles.map((role) => ({
|
|
49
|
+
return roles.map(role => ({
|
|
57
50
|
role_code: role.code,
|
|
58
51
|
name: role.name,
|
|
59
52
|
permission: moduleAccesses
|
|
60
|
-
.filter(
|
|
61
|
-
.map(
|
|
53
|
+
.filter(access => access.role_code === role.code)
|
|
54
|
+
.map(access => ({
|
|
62
55
|
action: access.action_type,
|
|
63
56
|
access: access.access_flag,
|
|
64
57
|
code: access.module_code,
|
|
@@ -67,62 +60,48 @@ export class ModuleAccessRepository {
|
|
|
67
60
|
}
|
|
68
61
|
|
|
69
62
|
async getMenuListing(mainModIds: string[]) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Fetch ALL MAINMOD modules if "-1" is passed
|
|
74
|
-
mainModules = await this.moduleRepo.find({
|
|
75
|
-
where: { module_level: 'MAINMOD' },
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
// Fetch selected MAINMOD modules
|
|
79
|
-
mainModules = await this.moduleRepo.find({
|
|
80
|
-
where: { id: In(mainModIds), module_level: 'MAINMOD' },
|
|
81
|
-
});
|
|
82
|
-
}
|
|
63
|
+
const mainModules = mainModIds.length === 1 && mainModIds[0] === '-1'
|
|
64
|
+
? await this.moduleRepo.find({ where: { module_level: 'MAINMOD' } })
|
|
65
|
+
: await this.moduleRepo.find({ where: { id: In(mainModIds), module_level: 'MAINMOD' } });
|
|
83
66
|
|
|
84
67
|
if (!mainModules.length) return [];
|
|
85
68
|
|
|
86
|
-
const wbsCodes = mainModules.map(
|
|
69
|
+
const wbsCodes = mainModules.map(mod => mod.wbs_code);
|
|
87
70
|
|
|
88
71
|
const modules = await this.moduleRepo
|
|
89
72
|
.createQueryBuilder('module')
|
|
90
73
|
.where(
|
|
91
|
-
wbsCodes
|
|
92
|
-
|
|
93
|
-
.join(' OR '),
|
|
94
|
-
Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
|
|
74
|
+
wbsCodes.map(code => `module.wbs_code LIKE :code${code}`).join(' OR '),
|
|
75
|
+
Object.fromEntries(wbsCodes.map(code => [`code${code}`, `${code}%`])),
|
|
95
76
|
)
|
|
96
77
|
.getMany();
|
|
97
78
|
|
|
98
79
|
const moduleActions = await this.moduleActionRepo.find();
|
|
99
80
|
|
|
100
|
-
const buildHierarchy = (parentWbs: string) =>
|
|
101
|
-
|
|
102
|
-
.filter(
|
|
103
|
-
(
|
|
104
|
-
|
|
105
|
-
mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
|
|
81
|
+
const buildHierarchy = (parentWbs: string): any[] =>
|
|
82
|
+
modules
|
|
83
|
+
.filter(mod =>
|
|
84
|
+
mod.wbs_code.startsWith(`${parentWbs}.`) &&
|
|
85
|
+
mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
|
|
106
86
|
)
|
|
107
|
-
.map(
|
|
87
|
+
.map(mod => ({
|
|
108
88
|
name: mod.name,
|
|
109
89
|
code: mod.module_code,
|
|
110
90
|
permission: moduleActions
|
|
111
|
-
.filter(
|
|
112
|
-
.map(
|
|
91
|
+
.filter(action => action.module_code === mod.module_code)
|
|
92
|
+
.map(action => ({
|
|
113
93
|
action: action.action_type,
|
|
114
94
|
name: action.action_type,
|
|
115
95
|
})),
|
|
116
96
|
submod: buildHierarchy(mod.wbs_code),
|
|
117
97
|
}));
|
|
118
|
-
};
|
|
119
98
|
|
|
120
|
-
return mainModules.map(
|
|
99
|
+
return mainModules.map(mod => ({
|
|
121
100
|
name: mod.name,
|
|
122
101
|
code: mod.module_code,
|
|
123
102
|
permission: moduleActions
|
|
124
|
-
.filter(
|
|
125
|
-
.map(
|
|
103
|
+
.filter(action => action.module_code === mod.module_code)
|
|
104
|
+
.map(action => ({
|
|
126
105
|
action: action.action_type,
|
|
127
106
|
name: action.action_type,
|
|
128
107
|
})),
|
|
@@ -130,27 +109,29 @@ export class ModuleAccessRepository {
|
|
|
130
109
|
}));
|
|
131
110
|
}
|
|
132
111
|
|
|
133
|
-
async updateModuleAccess(
|
|
112
|
+
async updateModuleAccess(accessList: {
|
|
113
|
+
role_code: string;
|
|
114
|
+
module_code: string;
|
|
115
|
+
action_type: string;
|
|
116
|
+
access_flag: number;
|
|
117
|
+
app_code: string;
|
|
118
|
+
}[]): Promise<boolean> {
|
|
134
119
|
try {
|
|
135
|
-
for (const access of
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
for (const access of accessList) {
|
|
121
|
+
const existing = await this.moduleAccessRepo.findOne({
|
|
122
|
+
where: {
|
|
123
|
+
role_code: access.role_code,
|
|
124
|
+
module_code: access.module_code,
|
|
125
|
+
action_type: access.action_type,
|
|
126
|
+
app_code: access.app_code,
|
|
127
|
+
},
|
|
141
128
|
});
|
|
142
129
|
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
await this.moduleAccessRepo.save(
|
|
130
|
+
if (existing) {
|
|
131
|
+
existing.access_flag = access.access_flag;
|
|
132
|
+
await this.moduleAccessRepo.save(existing);
|
|
146
133
|
} else {
|
|
147
|
-
await this.moduleAccessRepo.save(
|
|
148
|
-
role_code,
|
|
149
|
-
module_code,
|
|
150
|
-
action_type,
|
|
151
|
-
access_flag,
|
|
152
|
-
app_code,
|
|
153
|
-
});
|
|
134
|
+
await this.moduleAccessRepo.save(this.moduleAccessRepo.create(access));
|
|
154
135
|
}
|
|
155
136
|
}
|
|
156
137
|
return true;
|
|
@@ -161,7 +142,12 @@ export class ModuleAccessRepository {
|
|
|
161
142
|
}
|
|
162
143
|
|
|
163
144
|
async createRole(
|
|
164
|
-
|
|
145
|
+
{
|
|
146
|
+
name,
|
|
147
|
+
description,
|
|
148
|
+
status = 'ACTIVE',
|
|
149
|
+
copyFromRoleId,
|
|
150
|
+
}: {
|
|
165
151
|
name: string;
|
|
166
152
|
description?: string;
|
|
167
153
|
status?: 'ACTIVE' | 'INACTIVE';
|
|
@@ -169,59 +155,45 @@ export class ModuleAccessRepository {
|
|
|
169
155
|
},
|
|
170
156
|
loggedInUser: UserData,
|
|
171
157
|
) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const nameExists = await this.isRoleNameExists(name);
|
|
175
|
-
if (nameExists) {
|
|
158
|
+
if (await this.isRoleNameExists(name)) {
|
|
176
159
|
throw new BadRequestException('Role name already exists.');
|
|
177
160
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
161
|
+
|
|
162
|
+
const sourceRole = copyFromRoleId
|
|
163
|
+
? await this.roleRepo.findOne({ where: { id: copyFromRoleId } })
|
|
164
|
+
: null;
|
|
165
|
+
|
|
166
|
+
if (copyFromRoleId && !sourceRole) {
|
|
167
|
+
throw new BadRequestException('Source role not found.');
|
|
185
168
|
}
|
|
186
169
|
|
|
187
|
-
// 1. Create the role without the code (code will be updated after ID is generated)
|
|
188
170
|
const newRole = this.roleRepo.create({
|
|
189
171
|
name,
|
|
190
172
|
description,
|
|
191
|
-
status
|
|
173
|
+
status,
|
|
192
174
|
created_by: loggedInUser.id,
|
|
193
175
|
created_date: new Date(),
|
|
194
176
|
});
|
|
195
177
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
// 3. Generate the code using the saved ID
|
|
200
|
-
const generatedCode = `ROL${savedRole.id}`;
|
|
178
|
+
const savedRole = await this.roleRepo.save(newRole);
|
|
179
|
+
savedRole.code = `ROL${savedRole.id}`;
|
|
180
|
+
await this.roleRepo.save(savedRole);
|
|
201
181
|
|
|
202
|
-
|
|
203
|
-
savedRole.code = generatedCode;
|
|
204
|
-
await this.roleRepo.save(savedRole); // Update only the code
|
|
205
|
-
|
|
206
|
-
if (copyFromRoleId) {
|
|
207
|
-
const sourceRole = await this.roleRepo.findOne({
|
|
208
|
-
where: { id: copyFromRoleId },
|
|
209
|
-
});
|
|
210
|
-
if (!sourceRole) {
|
|
211
|
-
throw new BadRequestException('Source role not found');
|
|
212
|
-
}
|
|
182
|
+
if (sourceRole) {
|
|
213
183
|
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
214
184
|
where: { role_code: sourceRole.code },
|
|
215
185
|
});
|
|
216
|
-
|
|
186
|
+
|
|
187
|
+
const clonedPermissions = sourcePermissions.map(perm =>
|
|
217
188
|
this.moduleAccessRepo.create({
|
|
218
|
-
role_code:
|
|
189
|
+
role_code: savedRole.code,
|
|
219
190
|
module_code: perm.module_code,
|
|
220
191
|
action_type: perm.action_type,
|
|
221
192
|
access_flag: perm.access_flag,
|
|
222
193
|
app_code: perm.app_code,
|
|
223
194
|
}),
|
|
224
195
|
);
|
|
196
|
+
|
|
225
197
|
await this.moduleAccessRepo.save(clonedPermissions);
|
|
226
198
|
}
|
|
227
199
|
|
|
@@ -239,7 +211,12 @@ export class ModuleAccessRepository {
|
|
|
239
211
|
|
|
240
212
|
async updateRole(
|
|
241
213
|
roleId: number,
|
|
242
|
-
|
|
214
|
+
{
|
|
215
|
+
name,
|
|
216
|
+
description,
|
|
217
|
+
status = 'ACTIVE',
|
|
218
|
+
copyFromRoleId,
|
|
219
|
+
}: {
|
|
243
220
|
name: string;
|
|
244
221
|
description?: string;
|
|
245
222
|
status?: 'ACTIVE' | 'INACTIVE';
|
|
@@ -247,39 +224,38 @@ export class ModuleAccessRepository {
|
|
|
247
224
|
},
|
|
248
225
|
loggedInUser: UserData,
|
|
249
226
|
) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const nameExists = await this.isRoleNameExists(name, roleId);
|
|
253
|
-
if (nameExists) {
|
|
227
|
+
if (await this.isRoleNameExists(name, roleId)) {
|
|
254
228
|
throw new BadRequestException('Role name already exists.');
|
|
255
229
|
}
|
|
256
230
|
|
|
257
231
|
const role = await this.roleRepo.findOne({ where: { id: roleId } });
|
|
258
232
|
if (!role) {
|
|
259
|
-
throw new BadRequestException('
|
|
233
|
+
throw new BadRequestException('Role not found');
|
|
260
234
|
}
|
|
261
235
|
|
|
262
|
-
role
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
236
|
+
Object.assign(role, {
|
|
237
|
+
name,
|
|
238
|
+
description: description || '',
|
|
239
|
+
status,
|
|
240
|
+
modified_by: loggedInUser.id,
|
|
241
|
+
modified_date: new Date(),
|
|
242
|
+
});
|
|
243
|
+
|
|
267
244
|
await this.roleRepo.save(role);
|
|
268
245
|
|
|
269
246
|
if (copyFromRoleId) {
|
|
270
|
-
await this.
|
|
271
|
-
|
|
272
|
-
const sourceRole = await this.roleRepo.findOne({
|
|
273
|
-
where: { id: copyFromRoleId },
|
|
274
|
-
});
|
|
247
|
+
const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
|
|
275
248
|
if (!sourceRole) {
|
|
276
249
|
throw new BadRequestException('Source role not found');
|
|
277
250
|
}
|
|
278
251
|
|
|
252
|
+
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
253
|
+
|
|
279
254
|
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
280
255
|
where: { role_code: sourceRole.code },
|
|
281
256
|
});
|
|
282
|
-
|
|
257
|
+
|
|
258
|
+
const clonedPermissions = sourcePermissions.map(perm =>
|
|
283
259
|
this.moduleAccessRepo.create({
|
|
284
260
|
role_code: role.code,
|
|
285
261
|
module_code: perm.module_code,
|
|
@@ -288,6 +264,7 @@ export class ModuleAccessRepository {
|
|
|
288
264
|
app_code: perm.app_code,
|
|
289
265
|
}),
|
|
290
266
|
);
|
|
267
|
+
|
|
291
268
|
await this.moduleAccessRepo.save(clonedPermissions);
|
|
292
269
|
}
|
|
293
270
|
|
|
@@ -303,10 +280,7 @@ export class ModuleAccessRepository {
|
|
|
303
280
|
};
|
|
304
281
|
}
|
|
305
282
|
|
|
306
|
-
async isRoleNameExists(
|
|
307
|
-
name: string,
|
|
308
|
-
excludeRoleId?: number,
|
|
309
|
-
): Promise<boolean> {
|
|
283
|
+
private async isRoleNameExists(name: string, excludeRoleId?: number): Promise<boolean> {
|
|
310
284
|
const query = this.roleRepo
|
|
311
285
|
.createQueryBuilder('role')
|
|
312
286
|
.where('role.name = :name', { name });
|