rez_core 2.0.93 → 2.0.95
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/module/controller/module-access.controller.d.ts +3 -2
- package/dist/module/module/controller/module-access.controller.js +12 -10
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +4 -1
- package/dist/module/module/repository/module-access.repository.js +33 -6
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +4 -1
- package/dist/module/module/service/module-access.service.js +6 -2
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/module/controller/module-access.controller.ts +10 -17
- package/src/module/module/repository/module-access.repository.ts +50 -10
- package/src/module/module/service/module-access.service.ts +28 -11
package/package.json
CHANGED
|
@@ -13,10 +13,6 @@ import {
|
|
|
13
13
|
} from '@nestjs/common';
|
|
14
14
|
import { ModuleAccessService } from '../service/module-access.service';
|
|
15
15
|
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
16
|
-
import { ENTITYTYPE_USER } from '../../../constant/global.constant';
|
|
17
|
-
import { UserService } from '../../user/service/user.service';
|
|
18
|
-
import { UserData } from '../../user/entity/user.entity';
|
|
19
|
-
import { MenuRepository } from '../repository/menu.repository';
|
|
20
16
|
import { MenuService } from '../service/menu.service';
|
|
21
17
|
|
|
22
18
|
@Controller('module-access')
|
|
@@ -28,15 +24,14 @@ export class ModuleAccessController {
|
|
|
28
24
|
) {}
|
|
29
25
|
|
|
30
26
|
@Get('roles')
|
|
31
|
-
async getRoles(@Request() req) {
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
async getRoles(@Query('appcode') appcode: string, @Request() req) {
|
|
28
|
+
let level_type= req.user.userData.level_type
|
|
29
|
+
let level_id= req.user.userData.level_id
|
|
30
|
+
return this.moduleAccessService.getRoles({ appcode,level_type, level_id });
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
@Get('modules')
|
|
37
|
-
async getModules(@Request() req) {
|
|
38
|
-
const appcode = req.user.userData.appcode;
|
|
39
|
-
|
|
34
|
+
async getModules( @Query('appcode') appcode: string,@Request() req) {
|
|
40
35
|
return this.moduleAccessService.getModules({
|
|
41
36
|
appcode,
|
|
42
37
|
});
|
|
@@ -50,9 +45,9 @@ export class ModuleAccessController {
|
|
|
50
45
|
) {
|
|
51
46
|
const roleIdArray = roleIds.split(',').map(Number);
|
|
52
47
|
const appcode = queryAppcode || req.user.userData.appcode;
|
|
53
|
-
return this.moduleAccessService.getAccessListing(roleIdArray, appcode,
|
|
48
|
+
return this.moduleAccessService.getAccessListing(roleIdArray, appcode, '');
|
|
54
49
|
}
|
|
55
|
-
|
|
50
|
+
|
|
56
51
|
@Get('menu-listing')
|
|
57
52
|
async getMenuListing(
|
|
58
53
|
@Query('mainmod') mainModIds: string,
|
|
@@ -60,16 +55,14 @@ export class ModuleAccessController {
|
|
|
60
55
|
@Request() req,
|
|
61
56
|
) {
|
|
62
57
|
const mainModArray = mainModIds.split(',').map(String);
|
|
63
|
-
const { level_type} = req.user.userData;
|
|
64
|
-
|
|
58
|
+
const { level_type } = req.user.userData;
|
|
59
|
+
|
|
65
60
|
return this.moduleAccessService.getMenuListing(
|
|
66
61
|
mainModArray,
|
|
67
62
|
appcode,
|
|
68
|
-
level_type
|
|
63
|
+
level_type,
|
|
69
64
|
);
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
66
|
|
|
74
67
|
@Post('update')
|
|
75
68
|
async updateModuleAccess(@Body() moduleAccessData: any[], @Request() req) {
|
|
@@ -22,18 +22,43 @@ export class ModuleAccessRepository {
|
|
|
22
22
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
23
23
|
) {}
|
|
24
24
|
|
|
25
|
-
async getRoles({
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
async getRoles({
|
|
26
|
+
appcode,
|
|
27
|
+
level_type,
|
|
28
|
+
level_id,
|
|
29
|
+
}: {
|
|
30
|
+
appcode: string;
|
|
31
|
+
level_type?: string;
|
|
32
|
+
level_id?: number;
|
|
33
|
+
}) {
|
|
34
|
+
const where: any = { appcode };
|
|
35
|
+
if (level_type) where.level_type = level_type;
|
|
36
|
+
if (level_id !== undefined) where.level_id = String(level_id);
|
|
37
|
+
|
|
38
|
+
const roles = await this.roleRepo.find({ where });
|
|
39
|
+
|
|
40
|
+
return roles.map((role) => ({
|
|
41
|
+
label: role.name,
|
|
42
|
+
value: role.id,
|
|
43
|
+
}));
|
|
28
44
|
}
|
|
45
|
+
|
|
46
|
+
|
|
29
47
|
|
|
30
48
|
async getModules({ appcode }: { appcode: string }) {
|
|
31
49
|
const modules = await this.moduleRepo.find({
|
|
32
50
|
where: { module_level: 'MAINMOD', appcode },
|
|
33
51
|
});
|
|
34
|
-
|
|
52
|
+
|
|
53
|
+
return modules
|
|
54
|
+
.map((mod) => ({
|
|
55
|
+
label: mod.name,
|
|
56
|
+
value: mod.id,
|
|
57
|
+
group: mod.level_type,
|
|
58
|
+
}))
|
|
59
|
+
.sort((a, b) => a.group.localeCompare(b.group));
|
|
35
60
|
}
|
|
36
|
-
|
|
61
|
+
|
|
37
62
|
async getAccessListing(roleIds: number[], appcode: string, levelType: string) {
|
|
38
63
|
const roles = await this.roleRepo.find({
|
|
39
64
|
where: { id: In(roleIds), appcode },
|
|
@@ -62,7 +87,6 @@ export class ModuleAccessRepository {
|
|
|
62
87
|
}));
|
|
63
88
|
}
|
|
64
89
|
|
|
65
|
-
|
|
66
90
|
async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
|
|
67
91
|
const mainModules =
|
|
68
92
|
mainModIds.length === 1 && mainModIds[0] === '-1'
|
|
@@ -84,6 +108,23 @@ export class ModuleAccessRepository {
|
|
|
84
108
|
.andWhere('module.appcode = :appcode', { appcode })
|
|
85
109
|
.getMany();
|
|
86
110
|
|
|
111
|
+
const moduleCodes = allModules.map((m) => m.module_code);
|
|
112
|
+
|
|
113
|
+
const allActions = await this.moduleActionRepo.find({
|
|
114
|
+
where: { module_code: In(moduleCodes) },
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Map actions by module_code with full permission object
|
|
118
|
+
const actionMap = allActions.reduce((acc, action) => {
|
|
119
|
+
if (!acc[action.module_code]) acc[action.module_code] = [];
|
|
120
|
+
acc[action.module_code].push({
|
|
121
|
+
action: action.action_type,
|
|
122
|
+
name: action.action_name,
|
|
123
|
+
// You can also include action_type here if needed
|
|
124
|
+
});
|
|
125
|
+
return acc;
|
|
126
|
+
}, {} as Record<string, { action: string; name: string }[]>);
|
|
127
|
+
|
|
87
128
|
const levelsToReturn = levelType === 'ORG' ? ['ORG', 'SCH'] : ['SCH'];
|
|
88
129
|
|
|
89
130
|
const groupedByLevel: Record<string, any[]> = {};
|
|
@@ -101,7 +142,7 @@ export class ModuleAccessRepository {
|
|
|
101
142
|
.map((mod) => ({
|
|
102
143
|
name: mod.name,
|
|
103
144
|
code: mod.module_code,
|
|
104
|
-
permission: []
|
|
145
|
+
permission: actionMap[mod.module_code] || [],
|
|
105
146
|
submod: buildHierarchy(mod.wbs_code),
|
|
106
147
|
}));
|
|
107
148
|
|
|
@@ -110,7 +151,7 @@ export class ModuleAccessRepository {
|
|
|
110
151
|
.map((mod) => ({
|
|
111
152
|
name: mod.name,
|
|
112
153
|
code: mod.module_code,
|
|
113
|
-
permission: [],
|
|
154
|
+
permission: actionMap[mod.module_code] || [],
|
|
114
155
|
submod: buildHierarchy(mod.wbs_code),
|
|
115
156
|
}));
|
|
116
157
|
|
|
@@ -118,10 +159,9 @@ export class ModuleAccessRepository {
|
|
|
118
159
|
groupedByLevel[lvl] = levelModules;
|
|
119
160
|
}
|
|
120
161
|
}
|
|
121
|
-
|
|
122
162
|
return groupedByLevel;
|
|
123
163
|
}
|
|
124
|
-
|
|
164
|
+
|
|
125
165
|
|
|
126
166
|
async updateModuleAccess(
|
|
127
167
|
accessList: {
|
|
@@ -15,8 +15,20 @@ export class ModuleAccessService {
|
|
|
15
15
|
private readonly menuRepository: MenuRepository,
|
|
16
16
|
) {}
|
|
17
17
|
|
|
18
|
-
async getRoles({
|
|
19
|
-
|
|
18
|
+
async getRoles({
|
|
19
|
+
appcode,
|
|
20
|
+
level_type,
|
|
21
|
+
level_id,
|
|
22
|
+
}: {
|
|
23
|
+
appcode: string;
|
|
24
|
+
level_type?: string;
|
|
25
|
+
level_id?: number;
|
|
26
|
+
}) {
|
|
27
|
+
return this.moduleAccessRepository.getRoles({
|
|
28
|
+
appcode,
|
|
29
|
+
level_type,
|
|
30
|
+
level_id,
|
|
31
|
+
});
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
async getModules({ appcode }: { appcode: string }) {
|
|
@@ -29,9 +41,13 @@ export class ModuleAccessService {
|
|
|
29
41
|
appcode: string,
|
|
30
42
|
levelType: string,
|
|
31
43
|
) {
|
|
32
|
-
return this.moduleAccessRepository.getAccessListing(
|
|
44
|
+
return this.moduleAccessRepository.getAccessListing(
|
|
45
|
+
roleIds,
|
|
46
|
+
appcode,
|
|
47
|
+
levelType,
|
|
48
|
+
);
|
|
33
49
|
}
|
|
34
|
-
|
|
50
|
+
|
|
35
51
|
async getMenuListing(
|
|
36
52
|
mainModIds: string[],
|
|
37
53
|
appcode: string,
|
|
@@ -40,11 +56,13 @@ export class ModuleAccessService {
|
|
|
40
56
|
if (!appcode) {
|
|
41
57
|
throw new BadRequestException('Appcode is required');
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
return this.moduleAccessRepository.getAllModulesByLevel(
|
|
59
|
+
|
|
60
|
+
return this.moduleAccessRepository.getAllModulesByLevel(
|
|
61
|
+
mainModIds,
|
|
62
|
+
appcode,
|
|
63
|
+
levelType,
|
|
64
|
+
);
|
|
45
65
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
66
|
|
|
49
67
|
async updateModuleAccess(
|
|
50
68
|
moduleAccessData: {
|
|
@@ -60,12 +78,12 @@ export class ModuleAccessService {
|
|
|
60
78
|
if (!moduleAccessData || moduleAccessData.length === 0) {
|
|
61
79
|
return { success: false, msg: 'No data provided' };
|
|
62
80
|
}
|
|
63
|
-
|
|
81
|
+
|
|
64
82
|
const result = await this.moduleAccessRepository.updateModuleAccess(
|
|
65
83
|
moduleAccessData,
|
|
66
84
|
appcode,
|
|
67
85
|
);
|
|
68
|
-
|
|
86
|
+
|
|
69
87
|
if (result) {
|
|
70
88
|
return { success: true, msg: 'Module access updated successfully' };
|
|
71
89
|
} else {
|
|
@@ -73,7 +91,6 @@ export class ModuleAccessService {
|
|
|
73
91
|
}
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
|
|
77
94
|
// src/module/module-access/service/module-access.service.ts
|
|
78
95
|
|
|
79
96
|
async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
|