rez_core 1.0.47 → 1.0.49
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/data/master.xlsx +0 -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/master/service/master.service.d.ts +7 -1
- package/dist/module/master/service/master.service.js +72 -3
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/module/meta/controller/entity.controller.d.ts +6 -2
- package/dist/module/meta/controller/entity.controller.js +13 -6
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/module/meta/controller/media.controller.d.ts +1 -0
- package/dist/module/meta/controller/media.controller.js +27 -0
- package/dist/module/meta/controller/media.controller.js.map +1 -1
- package/dist/module/meta/entity/field-group.entity.d.ts +9 -0
- package/dist/module/meta/entity/field-group.entity.js +47 -0
- package/dist/module/meta/entity/field-group.entity.js.map +1 -0
- package/dist/module/meta/entity/school.entity.d.ts +8 -0
- package/dist/module/meta/entity/school.entity.js +44 -0
- package/dist/module/meta/entity/school.entity.js.map +1 -0
- package/dist/module/meta/entity/schoolAddress.entity.d.ts +9 -0
- package/dist/module/meta/entity/schoolAddress.entity.js +48 -0
- package/dist/module/meta/entity/schoolAddress.entity.js.map +1 -0
- package/dist/module/meta/entity/section-master.entity.d.ts +10 -0
- package/dist/module/meta/entity/section-master.entity.js +51 -0
- package/dist/module/meta/entity/section-master.entity.js.map +1 -0
- package/dist/module/meta/entity.module.js +19 -0
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/repository/attribute-master.repository.d.ts +1 -0
- package/dist/module/meta/repository/attribute-master.repository.js +7 -0
- package/dist/module/meta/repository/attribute-master.repository.js.map +1 -1
- package/dist/module/meta/service/attribute-master.service.d.ts +6 -0
- package/dist/module/meta/service/attribute-master.service.js +28 -0
- package/dist/module/meta/service/attribute-master.service.js.map +1 -0
- package/dist/module/meta/service/entity-list.service.js +1 -1
- package/dist/module/meta/service/entity-list.service.js.map +1 -1
- package/dist/module/meta/service/entity-master.service.d.ts +1 -0
- package/dist/module/meta/service/entity-master.service.js +6 -0
- package/dist/module/meta/service/entity-master.service.js.map +1 -1
- package/dist/module/meta/service/field-group.service.d.ts +26 -0
- package/dist/module/meta/service/field-group.service.js +78 -0
- package/dist/module/meta/service/field-group.service.js.map +1 -0
- package/dist/module/meta/service/media-data.service.d.ts +1 -0
- package/dist/module/meta/service/media-data.service.js +15 -0
- package/dist/module/meta/service/media-data.service.js.map +1 -1
- package/dist/module/meta/service/section-master.service.d.ts +26 -0
- package/dist/module/meta/service/section-master.service.js +78 -0
- package/dist/module/meta/service/section-master.service.js.map +1 -0
- package/dist/module/meta/service/view-master.service.d.ts +5 -1
- package/dist/module/meta/service/view-master.service.js +32 -2
- package/dist/module/meta/service/view-master.service.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.d.ts +7 -1
- package/dist/module/module/controller/module-access.controller.js +19 -8
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +3 -2
- package/dist/module/module/repository/module-access.repository.js +30 -13
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +8 -3
- package/dist/module/module/service/module-access.service.js +35 -7
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/user/entity/user-role-mapping.entity.d.ts +1 -0
- package/dist/module/user/entity/user-role-mapping.entity.js +6 -0
- package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/constant/global.constant.ts +5 -1
- package/src/module/master/service/master.service.ts +98 -3
- package/src/module/meta/controller/entity.controller.ts +14 -3
- package/src/module/meta/controller/media.controller.ts +27 -1
- package/src/module/meta/entity/field-group.entity.ts +25 -0
- package/src/module/meta/entity/school.entity.ts +23 -0
- package/src/module/meta/entity/schoolAddress.entity.ts +25 -0
- package/src/module/meta/entity/section-master.entity.ts +28 -0
- package/src/module/meta/entity.module.ts +19 -0
- package/src/module/meta/repository/attribute-master.repository.ts +11 -1
- package/src/module/meta/service/attribute-master.service.ts +17 -0
- package/src/module/meta/service/entity-list.service.ts +1 -1
- package/src/module/meta/service/entity-master.service.ts +7 -0
- package/src/module/meta/service/field-group.service.ts +104 -0
- package/src/module/meta/service/media-data.service.ts +22 -9
- package/src/module/meta/service/section-master.service.ts +104 -0
- package/src/module/meta/service/view-master.service.ts +42 -4
- package/src/module/module/controller/module-access.controller.ts +16 -4
- package/src/module/module/repository/module-access.repository.ts +81 -47
- package/src/module/module/service/module-access.service.ts +60 -21
- package/src/module/user/entity/user-role-mapping.entity.ts +26 -21
- package/src/module/user/service/role.service.ts +1 -0
- package/src/resources/dev.properties.yaml +6 -6
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { EntityServiceImpl } from './entity-service-impl.service';
|
|
3
|
+
import { BaseEntity } from '../entity/base-entity.entity';
|
|
4
|
+
import { UserData } from '../../user/entity/user.entity';
|
|
5
|
+
import { EntityManager } from 'typeorm';
|
|
6
|
+
import { ViewMaster } from '../entity/view-master.entity';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class SectionMasterService extends EntityServiceImpl {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async createEntity(
|
|
15
|
+
entityData: BaseEntity,
|
|
16
|
+
loggedInUser: UserData | null,
|
|
17
|
+
manager?: EntityManager,
|
|
18
|
+
): Promise<BaseEntity> {
|
|
19
|
+
const entityMaster = await this.entityMasterService.getEntityData(
|
|
20
|
+
entityData.entity_type,
|
|
21
|
+
);
|
|
22
|
+
entityData.parent_id = entityMaster.id;
|
|
23
|
+
entityData.parent_type = entityMaster.entity_type;
|
|
24
|
+
|
|
25
|
+
const savedEntity = await super.createEntity(
|
|
26
|
+
entityData,
|
|
27
|
+
loggedInUser,
|
|
28
|
+
manager,
|
|
29
|
+
);
|
|
30
|
+
return savedEntity;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async updateEntity(
|
|
34
|
+
entityData: ViewMaster,
|
|
35
|
+
loggedInUserData: UserData | null,
|
|
36
|
+
): Promise<BaseEntity> {
|
|
37
|
+
return entityData;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
parseLayout(layoutJson: any) {
|
|
41
|
+
const stepsData: {
|
|
42
|
+
stepType: string;
|
|
43
|
+
stepId: string;
|
|
44
|
+
stepLabel: string;
|
|
45
|
+
stepPosition: number;
|
|
46
|
+
fieldsGroup: {
|
|
47
|
+
type: string;
|
|
48
|
+
label: string;
|
|
49
|
+
id: string;
|
|
50
|
+
}[];
|
|
51
|
+
}[] = [];
|
|
52
|
+
|
|
53
|
+
if (layoutJson?.form?.children && Array.isArray(layoutJson.form.children)) {
|
|
54
|
+
const firstChild = layoutJson.form.children[0];
|
|
55
|
+
console.log('First Child:', firstChild);
|
|
56
|
+
|
|
57
|
+
if (firstChild.type === 'wizard' && Array.isArray(firstChild.steps)) {
|
|
58
|
+
console.log('Wizard Steps:', firstChild.steps);
|
|
59
|
+
let i = 0;
|
|
60
|
+
for (const step of firstChild.steps) {
|
|
61
|
+
if (step.type === 'step') {
|
|
62
|
+
const fields = this.extractFields(step.fields);
|
|
63
|
+
|
|
64
|
+
stepsData.push({
|
|
65
|
+
stepType: step.type,
|
|
66
|
+
stepId: step.id,
|
|
67
|
+
stepLabel: step.label,
|
|
68
|
+
stepPosition: ++i,
|
|
69
|
+
fieldsGroup: fields,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return stepsData;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
extractFields(fieldsArray: any[]): {
|
|
79
|
+
type: string;
|
|
80
|
+
label: string;
|
|
81
|
+
id: string;
|
|
82
|
+
}[] {
|
|
83
|
+
const extractedFields: { type: string; label: string; id: string }[] = [];
|
|
84
|
+
|
|
85
|
+
function traverse(fields: any[]) {
|
|
86
|
+
for (const field of fields) {
|
|
87
|
+
if (field.type === 'field-set') {
|
|
88
|
+
extractedFields.push({
|
|
89
|
+
type: field.type || 'Default Type',
|
|
90
|
+
label: field.label || 'Default Label',
|
|
91
|
+
id: field.id || 'Default ID',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(field.fields)) {
|
|
95
|
+
traverse(field.fields);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
traverse(fieldsArray);
|
|
101
|
+
|
|
102
|
+
return extractedFields;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -4,10 +4,16 @@ import { BaseEntity } from '../entity/base-entity.entity';
|
|
|
4
4
|
import { UserData } from '../../user/entity/user.entity';
|
|
5
5
|
import { EntityManager } from 'typeorm';
|
|
6
6
|
import { ViewMaster } from '../entity/view-master.entity';
|
|
7
|
-
|
|
7
|
+
import { SectionMasterService } from './section-master.service';
|
|
8
|
+
import { SectionMaster } from '../entity/section-master.entity';
|
|
9
|
+
import { FieldGroup } from '../entity/field-group.entity';
|
|
10
|
+
import { FieldGroupService } from './field-group.service';
|
|
8
11
|
@Injectable()
|
|
9
12
|
export class ViewMasterService extends EntityServiceImpl {
|
|
10
|
-
constructor(
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly sectionMasterService: SectionMasterService,
|
|
15
|
+
private readonly fieldGroupService: FieldGroupService,
|
|
16
|
+
) {
|
|
11
17
|
super();
|
|
12
18
|
}
|
|
13
19
|
|
|
@@ -27,6 +33,40 @@ export class ViewMasterService extends EntityServiceImpl {
|
|
|
27
33
|
loggedInUser,
|
|
28
34
|
manager,
|
|
29
35
|
);
|
|
36
|
+
let viewMaster = savedEntity as ViewMaster;
|
|
37
|
+
|
|
38
|
+
let layout = viewMaster.published_form_layout;
|
|
39
|
+
|
|
40
|
+
const stepsData = this.sectionMasterService.parseLayout(layout);
|
|
41
|
+
for (var step of stepsData) {
|
|
42
|
+
let sectionMaster = new SectionMaster();
|
|
43
|
+
sectionMaster.name = step.stepLabel;
|
|
44
|
+
sectionMaster.position = step.stepPosition;
|
|
45
|
+
sectionMaster.description = step.stepLabel;
|
|
46
|
+
sectionMaster.parent_id = viewMaster.id;
|
|
47
|
+
sectionMaster.parent_type = viewMaster.entity_type;
|
|
48
|
+
|
|
49
|
+
const savedSectionMaster = await this.sectionMasterService.createEntity(
|
|
50
|
+
sectionMaster,
|
|
51
|
+
loggedInUser,
|
|
52
|
+
manager,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const fieldGroups = step.fieldsGroup;
|
|
56
|
+
console.log('fieldGroups', fieldGroups);
|
|
57
|
+
|
|
58
|
+
for (var fieldGroup of fieldGroups) {
|
|
59
|
+
let fieldsGroup = new FieldGroup();
|
|
60
|
+
fieldsGroup.view_id = viewMaster.id;
|
|
61
|
+
fieldsGroup.parent_id = savedSectionMaster.id;
|
|
62
|
+
fieldsGroup.field_type = fieldGroup.type;
|
|
63
|
+
fieldsGroup.label = fieldGroup.label;
|
|
64
|
+
fieldsGroup.description = fieldGroup.label;
|
|
65
|
+
|
|
66
|
+
this.fieldGroupService.createEntity(fieldsGroup, loggedInUser, manager);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
30
70
|
return savedEntity;
|
|
31
71
|
}
|
|
32
72
|
|
|
@@ -34,8 +74,6 @@ export class ViewMasterService extends EntityServiceImpl {
|
|
|
34
74
|
entityData: ViewMaster,
|
|
35
75
|
loggedInUserData: UserData | null,
|
|
36
76
|
): Promise<BaseEntity> {
|
|
37
|
-
|
|
38
77
|
return entityData;
|
|
39
78
|
}
|
|
40
|
-
|
|
41
79
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
|
|
1
|
+
import { Body, Controller, Get, Inject, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
|
|
2
2
|
import { ModuleAccessService } from '../service/module-access.service';
|
|
3
3
|
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
4
|
+
import { ENTITYTYPE_USER } from '../../../constant/global.constant';
|
|
5
|
+
import { UserService } from '../../user/service/user.service';
|
|
6
|
+
import { UserData } from '../../user/entity/user.entity';
|
|
4
7
|
|
|
5
8
|
@Controller('module-access')
|
|
6
9
|
@UseGuards(JwtAuthGuard)
|
|
7
10
|
export class ModuleAccessController {
|
|
8
|
-
constructor(private readonly moduleAccessService: ModuleAccessService
|
|
11
|
+
constructor(private readonly moduleAccessService: ModuleAccessService,
|
|
12
|
+
@Inject('UserService') private readonly userService: UserService,
|
|
13
|
+
) {}
|
|
9
14
|
|
|
10
15
|
@Get('roles')
|
|
11
16
|
async getRoles() {
|
|
@@ -43,8 +48,12 @@ export class ModuleAccessController {
|
|
|
43
48
|
status?: 'ACTIVE' | 'INACTIVE';
|
|
44
49
|
copyFromRoleId?: number;
|
|
45
50
|
},
|
|
51
|
+
@Req() req: Request & {user: any}
|
|
46
52
|
) {
|
|
47
|
-
|
|
53
|
+
|
|
54
|
+
let requestedUser = req.user;
|
|
55
|
+
let loggedInUser = await this.userService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
|
|
56
|
+
return this.moduleAccessService.createRole(body, loggedInUser as UserData);
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
@Post('update-role/:id')
|
|
@@ -57,8 +66,11 @@ export class ModuleAccessController {
|
|
|
57
66
|
status?: 'ACTIVE' | 'INACTIVE';
|
|
58
67
|
copyFromRoleId?: number; // <-- ADD THIS
|
|
59
68
|
},
|
|
69
|
+
@Req() req: Request & {user: any}
|
|
60
70
|
) {
|
|
61
|
-
|
|
71
|
+
let requestedUser = req.user;
|
|
72
|
+
let loggedInUser = await this.userService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
|
|
73
|
+
return this.moduleAccessService.updateRole(id, body, loggedInUser as UserData);
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
|
|
@@ -6,6 +6,7 @@ import { ModuleAccess } from '../entity/module-access.entity';
|
|
|
6
6
|
import { ModuleAction } from '../entity/module-action.entity';
|
|
7
7
|
import { ModuleData } from '../entity/module.entity';
|
|
8
8
|
import { ClockIDGenService } from 'src/utils/service/clockIDGenUtil.service';
|
|
9
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
9
10
|
|
|
10
11
|
@Injectable()
|
|
11
12
|
export class ModuleAccessRepository {
|
|
@@ -18,27 +19,26 @@ export class ModuleAccessRepository {
|
|
|
18
19
|
private readonly moduleAccessRepo: Repository<ModuleAccess>,
|
|
19
20
|
@InjectRepository(ModuleAction)
|
|
20
21
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
private readonly clockIDGenService: ClockIDGenService,
|
|
23
23
|
) {}
|
|
24
24
|
|
|
25
25
|
async getRoles() {
|
|
26
26
|
const roles = await this.roleRepo.find();
|
|
27
|
-
return roles.map(role => ({
|
|
27
|
+
return roles.map((role) => ({
|
|
28
28
|
label: role.name,
|
|
29
29
|
value: role.id,
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
|
-
|
|
33
32
|
|
|
34
33
|
async getModules() {
|
|
35
|
-
const modules = await this.moduleRepo.find({
|
|
36
|
-
|
|
34
|
+
const modules = await this.moduleRepo.find({
|
|
35
|
+
where: { module_level: 'MAINMOD' },
|
|
36
|
+
});
|
|
37
|
+
return modules.map((mod) => ({
|
|
37
38
|
label: mod.name,
|
|
38
39
|
value: mod.id,
|
|
39
40
|
}));
|
|
40
41
|
}
|
|
41
|
-
|
|
42
42
|
|
|
43
43
|
async getAccessListing(roleIds: number[]) {
|
|
44
44
|
// Fetch roles using role IDs
|
|
@@ -68,21 +68,23 @@ export class ModuleAccessRepository {
|
|
|
68
68
|
|
|
69
69
|
async getMenuListing(mainModIds: string[]) {
|
|
70
70
|
let mainModules: ModuleData[] = [];
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
if (mainModIds.length === 1 && mainModIds[0] === '-1') {
|
|
73
73
|
// Fetch ALL MAINMOD modules if "-1" is passed
|
|
74
|
-
mainModules = await this.moduleRepo.find({
|
|
74
|
+
mainModules = await this.moduleRepo.find({
|
|
75
|
+
where: { module_level: 'MAINMOD' },
|
|
76
|
+
});
|
|
75
77
|
} else {
|
|
76
78
|
// Fetch selected MAINMOD modules
|
|
77
79
|
mainModules = await this.moduleRepo.find({
|
|
78
80
|
where: { id: In(mainModIds), module_level: 'MAINMOD' },
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
|
|
82
84
|
if (!mainModules.length) return [];
|
|
83
|
-
|
|
85
|
+
|
|
84
86
|
const wbsCodes = mainModules.map((mod) => mod.wbs_code);
|
|
85
|
-
|
|
87
|
+
|
|
86
88
|
const modules = await this.moduleRepo
|
|
87
89
|
.createQueryBuilder('module')
|
|
88
90
|
.where(
|
|
@@ -92,14 +94,15 @@ export class ModuleAccessRepository {
|
|
|
92
94
|
Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
|
|
93
95
|
)
|
|
94
96
|
.getMany();
|
|
95
|
-
|
|
97
|
+
|
|
96
98
|
const moduleActions = await this.moduleActionRepo.find();
|
|
97
|
-
|
|
99
|
+
|
|
98
100
|
const buildHierarchy = (parentWbs: string) => {
|
|
99
101
|
return modules
|
|
100
|
-
.filter(
|
|
101
|
-
mod
|
|
102
|
-
|
|
102
|
+
.filter(
|
|
103
|
+
(mod) =>
|
|
104
|
+
mod.wbs_code.startsWith(parentWbs + '.') &&
|
|
105
|
+
mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
|
|
103
106
|
)
|
|
104
107
|
.map((mod) => ({
|
|
105
108
|
name: mod.name,
|
|
@@ -113,7 +116,7 @@ export class ModuleAccessRepository {
|
|
|
113
116
|
submod: buildHierarchy(mod.wbs_code),
|
|
114
117
|
}));
|
|
115
118
|
};
|
|
116
|
-
|
|
119
|
+
|
|
117
120
|
return mainModules.map((mod) => ({
|
|
118
121
|
name: mod.name,
|
|
119
122
|
code: mod.module_code,
|
|
@@ -126,7 +129,7 @@ export class ModuleAccessRepository {
|
|
|
126
129
|
submod: buildHierarchy(mod.wbs_code),
|
|
127
130
|
}));
|
|
128
131
|
}
|
|
129
|
-
|
|
132
|
+
|
|
130
133
|
async updateModuleAccess(moduleAccessData: any[]): Promise<boolean> {
|
|
131
134
|
try {
|
|
132
135
|
for (const access of moduleAccessData) {
|
|
@@ -157,30 +160,44 @@ export class ModuleAccessRepository {
|
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
async createRole(
|
|
163
|
+
async createRole(
|
|
164
|
+
body: {
|
|
165
|
+
name: string;
|
|
166
|
+
description?: string;
|
|
167
|
+
status?: 'ACTIVE' | 'INACTIVE';
|
|
168
|
+
copyFromRoleId?: number;
|
|
169
|
+
},
|
|
170
|
+
loggedInUser: UserData,
|
|
171
|
+
) {
|
|
161
172
|
const { name, description, status, copyFromRoleId } = body;
|
|
162
|
-
|
|
173
|
+
|
|
163
174
|
const nameExists = await this.isRoleNameExists(name);
|
|
164
175
|
if (nameExists) {
|
|
165
176
|
throw new BadRequestException('Role name already exists.');
|
|
166
177
|
}
|
|
167
|
-
|
|
178
|
+
|
|
168
179
|
const code = this.clockIDGenService.idGenerator('ROL');
|
|
169
180
|
const newRole = this.roleRepo.create({
|
|
170
181
|
name,
|
|
171
182
|
code,
|
|
172
183
|
description,
|
|
173
184
|
status: status || 'ACTIVE',
|
|
185
|
+
created_by: loggedInUser.id,
|
|
186
|
+
created_date: new Date(),
|
|
174
187
|
});
|
|
175
|
-
|
|
188
|
+
|
|
176
189
|
const savedRole = await this.roleRepo.save(newRole);
|
|
177
|
-
|
|
190
|
+
|
|
178
191
|
if (copyFromRoleId) {
|
|
179
|
-
const sourceRole = await this.roleRepo.findOne({
|
|
192
|
+
const sourceRole = await this.roleRepo.findOne({
|
|
193
|
+
where: { id: copyFromRoleId },
|
|
194
|
+
});
|
|
180
195
|
if (!sourceRole) {
|
|
181
196
|
throw new BadRequestException('Source role not found');
|
|
182
197
|
}
|
|
183
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
198
|
+
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
199
|
+
where: { role_code: sourceRole.code },
|
|
200
|
+
});
|
|
184
201
|
const clonedPermissions = sourcePermissions.map((perm) =>
|
|
185
202
|
this.moduleAccessRepo.create({
|
|
186
203
|
role_code: code,
|
|
@@ -188,11 +205,11 @@ export class ModuleAccessRepository {
|
|
|
188
205
|
action_type: perm.action_type,
|
|
189
206
|
access_flag: perm.access_flag,
|
|
190
207
|
app_code: perm.app_code,
|
|
191
|
-
})
|
|
208
|
+
}),
|
|
192
209
|
);
|
|
193
210
|
await this.moduleAccessRepo.save(clonedPermissions);
|
|
194
211
|
}
|
|
195
|
-
|
|
212
|
+
|
|
196
213
|
return {
|
|
197
214
|
success: true,
|
|
198
215
|
msg: 'Role created successfully',
|
|
@@ -204,35 +221,49 @@ export class ModuleAccessRepository {
|
|
|
204
221
|
},
|
|
205
222
|
};
|
|
206
223
|
}
|
|
207
|
-
|
|
208
224
|
|
|
209
|
-
async updateRole(
|
|
225
|
+
async updateRole(
|
|
226
|
+
roleId: number,
|
|
227
|
+
body: {
|
|
228
|
+
name: string;
|
|
229
|
+
description?: string;
|
|
230
|
+
status?: 'ACTIVE' | 'INACTIVE';
|
|
231
|
+
copyFromRoleId?: number;
|
|
232
|
+
},
|
|
233
|
+
loggedInUser: UserData,
|
|
234
|
+
) {
|
|
210
235
|
const { name, description, status, copyFromRoleId } = body;
|
|
211
|
-
|
|
236
|
+
|
|
212
237
|
const nameExists = await this.isRoleNameExists(name, roleId);
|
|
213
238
|
if (nameExists) {
|
|
214
239
|
throw new BadRequestException('Role name already exists.');
|
|
215
240
|
}
|
|
216
|
-
|
|
241
|
+
|
|
217
242
|
const role = await this.roleRepo.findOne({ where: { id: roleId } });
|
|
218
243
|
if (!role) {
|
|
219
244
|
throw new BadRequestException('Source role not found');
|
|
220
245
|
}
|
|
221
|
-
|
|
246
|
+
|
|
222
247
|
role.name = name;
|
|
223
|
-
role.description = description ||
|
|
248
|
+
role.description = description || '';
|
|
224
249
|
role.status = status || 'ACTIVE';
|
|
250
|
+
role.modified_date = new Date();
|
|
251
|
+
role.modified_by = loggedInUser.id;
|
|
225
252
|
await this.roleRepo.save(role);
|
|
226
|
-
|
|
253
|
+
|
|
227
254
|
if (copyFromRoleId) {
|
|
228
255
|
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
229
|
-
|
|
230
|
-
const sourceRole = await this.roleRepo.findOne({
|
|
256
|
+
|
|
257
|
+
const sourceRole = await this.roleRepo.findOne({
|
|
258
|
+
where: { id: copyFromRoleId },
|
|
259
|
+
});
|
|
231
260
|
if (!sourceRole) {
|
|
232
261
|
throw new BadRequestException('Source role not found');
|
|
233
262
|
}
|
|
234
|
-
|
|
235
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
263
|
+
|
|
264
|
+
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
265
|
+
where: { role_code: sourceRole.code },
|
|
266
|
+
});
|
|
236
267
|
const clonedPermissions = sourcePermissions.map((perm) =>
|
|
237
268
|
this.moduleAccessRepo.create({
|
|
238
269
|
role_code: role.code,
|
|
@@ -240,11 +271,11 @@ export class ModuleAccessRepository {
|
|
|
240
271
|
action_type: perm.action_type,
|
|
241
272
|
access_flag: perm.access_flag,
|
|
242
273
|
app_code: perm.app_code,
|
|
243
|
-
})
|
|
274
|
+
}),
|
|
244
275
|
);
|
|
245
276
|
await this.moduleAccessRepo.save(clonedPermissions);
|
|
246
277
|
}
|
|
247
|
-
|
|
278
|
+
|
|
248
279
|
return {
|
|
249
280
|
success: true,
|
|
250
281
|
msg: 'Role updated successfully',
|
|
@@ -256,17 +287,20 @@ export class ModuleAccessRepository {
|
|
|
256
287
|
},
|
|
257
288
|
};
|
|
258
289
|
}
|
|
259
|
-
|
|
260
|
-
async isRoleNameExists(
|
|
261
|
-
|
|
290
|
+
|
|
291
|
+
async isRoleNameExists(
|
|
292
|
+
name: string,
|
|
293
|
+
excludeRoleId?: number,
|
|
294
|
+
): Promise<boolean> {
|
|
295
|
+
const query = this.roleRepo
|
|
296
|
+
.createQueryBuilder('role')
|
|
262
297
|
.where('role.name = :name', { name });
|
|
263
|
-
|
|
298
|
+
|
|
264
299
|
if (excludeRoleId) {
|
|
265
300
|
query.andWhere('role.id != :excludeRoleId', { excludeRoleId });
|
|
266
301
|
}
|
|
267
|
-
|
|
302
|
+
|
|
268
303
|
const existingRole = await query.getOne();
|
|
269
304
|
return !!existingRole;
|
|
270
305
|
}
|
|
271
|
-
|
|
272
306
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
1
|
+
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
|
2
2
|
import { ModuleAccessRepository } from '../repository/module-access.repository';
|
|
3
|
+
import { RoleRepository } from 'src/module/user/repository/role.repository';
|
|
4
|
+
import { RoleService } from '../../user/service/role.service';
|
|
5
|
+
import { ENTITYTYPE_ROLE } from '../../../constant/global.constant';
|
|
6
|
+
import { Role } from '../../user/entity/role.entity';
|
|
7
|
+
import { EntityManager } from 'typeorm';
|
|
8
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
3
9
|
|
|
4
10
|
@Injectable()
|
|
5
11
|
export class ModuleAccessService {
|
|
6
12
|
constructor(
|
|
7
13
|
private readonly moduleAccessRepository: ModuleAccessRepository,
|
|
14
|
+
@Inject('RoleService') private readonly roleService: RoleService,
|
|
15
|
+
private readonly entityManager: EntityManager,
|
|
8
16
|
) {}
|
|
9
17
|
|
|
10
18
|
async getRoles() {
|
|
@@ -40,33 +48,64 @@ export class ModuleAccessService {
|
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
async createRole(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
async createRole(
|
|
52
|
+
body: {
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
status?: 'ACTIVE' | 'INACTIVE';
|
|
56
|
+
copyFromRoleId?: number;
|
|
57
|
+
},
|
|
58
|
+
loggedInUser: UserData,
|
|
59
|
+
) {
|
|
60
|
+
return this.moduleAccessRepository.createRole(body, loggedInUser);
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
async updateRole(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
async updateRole(
|
|
64
|
+
id: number,
|
|
65
|
+
body: {
|
|
66
|
+
name?: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
status?: 'ACTIVE' | 'INACTIVE';
|
|
69
|
+
copyFromRoleId?: number;
|
|
70
|
+
},
|
|
71
|
+
loggedInUser: UserData,
|
|
72
|
+
) {
|
|
58
73
|
if (!body.name) {
|
|
59
|
-
throw new
|
|
74
|
+
throw new BadRequestException('Role name is required');
|
|
60
75
|
}
|
|
61
|
-
|
|
76
|
+
|
|
77
|
+
if (body.status === 'INACTIVE') {
|
|
78
|
+
//get role by id
|
|
79
|
+
const entityData = await this.roleService.getEntityData(
|
|
80
|
+
ENTITYTYPE_ROLE,
|
|
81
|
+
id,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const associatedUsers = await this.entityManager.query(`SELECT map.*
|
|
85
|
+
FROM cr_user_role_mapping map
|
|
86
|
+
JOIN cr_user usr ON map.user_id = usr.id
|
|
87
|
+
WHERE usr.status = 'ACTIVE' and map.role_id = ${entityData?.id}`);
|
|
88
|
+
|
|
89
|
+
if (associatedUsers.length > 0) {
|
|
90
|
+
throw new BadRequestException(
|
|
91
|
+
'Cannot deactivate role as it is associated with active users',
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!entityData) {
|
|
96
|
+
throw new BadRequestException('Role not found');
|
|
97
|
+
}
|
|
98
|
+
const role = entityData as Role;
|
|
99
|
+
if (role.is_system === 1) {
|
|
100
|
+
throw new BadRequestException('Cannot deactivate system role');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
62
104
|
return this.moduleAccessRepository.updateRole(id, {
|
|
63
105
|
name: body.name,
|
|
64
106
|
description: body.description,
|
|
65
107
|
status: body.status,
|
|
66
108
|
copyFromRoleId: body.copyFromRoleId,
|
|
67
|
-
});
|
|
109
|
+
}, loggedInUser);
|
|
68
110
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
111
|
+
}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
1
|
+
import { ENTITYTYPE_USRROLMAP } from 'src/constant/global.constant';
|
|
2
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
3
|
+
|
|
4
|
+
@Entity({ name: 'cr_user_role_mapping' })
|
|
5
|
+
export class UserRoleMapping {
|
|
6
|
+
constructor(user_id: number, role_id: number) {
|
|
7
|
+
this.user_id = user_id;
|
|
8
|
+
this.role_id = role_id;
|
|
9
|
+
this.entity_type = ENTITYTYPE_USRROLMAP;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@PrimaryGeneratedColumn()
|
|
13
|
+
id: number;
|
|
14
|
+
|
|
15
|
+
@Column({type: 'varchar'})
|
|
16
|
+
entity_type: string;
|
|
17
|
+
|
|
18
|
+
@Column({ type: 'bigint', nullable: true })
|
|
19
|
+
user_id: number;
|
|
20
|
+
|
|
21
|
+
@Column({ type: 'bigint', nullable: true })
|
|
22
|
+
role_id: number;
|
|
23
|
+
|
|
24
|
+
@Column({ type: 'int', nullable: true })
|
|
25
|
+
is_default: number;
|
|
26
|
+
}
|
|
@@ -13,9 +13,9 @@ OTP_EXPIRY: "10"
|
|
|
13
13
|
OTP_LENGTH: "6"
|
|
14
14
|
VERIFY_OTP: "false"
|
|
15
15
|
DEFAULT_OTP: "123456"
|
|
16
|
-
AWS:
|
|
17
|
-
S3:
|
|
18
|
-
AWS_ACCESS_KEY_ID: "
|
|
19
|
-
AWS_SECRET_KEY: "
|
|
20
|
-
AWS_REGION: "ap-south-1"
|
|
21
|
-
BUCKET_NAME: "testether"
|
|
16
|
+
#AWS:
|
|
17
|
+
# S3:
|
|
18
|
+
# AWS_ACCESS_KEY_ID: "AKIAYYKIBDDSQF3KILGE"
|
|
19
|
+
# AWS_SECRET_KEY: "PPDMAeO2mVUY1w2f46n/dlt5l9+7NY7E9twJb9LU"
|
|
20
|
+
# AWS_REGION: "ap-south-1"
|
|
21
|
+
# BUCKET_NAME: "testether"
|