rez_core 2.0.94 → 2.0.96
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 +4 -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 +5 -1
- package/dist/module/module/repository/module-access.repository.js +27 -8
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +5 -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 +66 -31
- 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) {
|
|
@@ -5,6 +5,7 @@ import { Role } from 'src/module/user/entity/role.entity';
|
|
|
5
5
|
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
|
+
import { level } from 'winston';
|
|
8
9
|
|
|
9
10
|
@Injectable()
|
|
10
11
|
export class ModuleAccessRepository {
|
|
@@ -22,19 +23,46 @@ export class ModuleAccessRepository {
|
|
|
22
23
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
23
24
|
) {}
|
|
24
25
|
|
|
25
|
-
async getRoles({
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
async getRoles({
|
|
27
|
+
appcode,
|
|
28
|
+
level_type,
|
|
29
|
+
level_id,
|
|
30
|
+
}: {
|
|
31
|
+
appcode: string;
|
|
32
|
+
level_type?: string;
|
|
33
|
+
level_id?: number;
|
|
34
|
+
}) {
|
|
35
|
+
const where: any = { appcode };
|
|
36
|
+
if (level_type) where.level_type = level_type;
|
|
37
|
+
if (level_id !== undefined) where.level_id = String(level_id);
|
|
38
|
+
|
|
39
|
+
const roles = await this.roleRepo.find({ where });
|
|
40
|
+
|
|
41
|
+
return roles.map((role) => ({
|
|
42
|
+
label: role.name,
|
|
43
|
+
value: role.id,
|
|
44
|
+
}));
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
async getModules({ appcode }: { appcode: string }) {
|
|
31
48
|
const modules = await this.moduleRepo.find({
|
|
32
49
|
where: { module_level: 'MAINMOD', appcode },
|
|
33
50
|
});
|
|
34
|
-
|
|
51
|
+
|
|
52
|
+
return modules
|
|
53
|
+
.map((mod) => ({
|
|
54
|
+
label: mod.name,
|
|
55
|
+
value: mod.id,
|
|
56
|
+
group: mod.level_type,
|
|
57
|
+
}))
|
|
58
|
+
.sort((a, b) => a.group.localeCompare(b.group));
|
|
35
59
|
}
|
|
36
60
|
|
|
37
|
-
async getAccessListing(
|
|
61
|
+
async getAccessListing(
|
|
62
|
+
roleIds: number[],
|
|
63
|
+
appcode: string,
|
|
64
|
+
levelType: string,
|
|
65
|
+
) {
|
|
38
66
|
const roles = await this.roleRepo.find({
|
|
39
67
|
where: { id: In(roleIds), appcode },
|
|
40
68
|
});
|
|
@@ -45,7 +73,6 @@ export class ModuleAccessRepository {
|
|
|
45
73
|
where: {
|
|
46
74
|
role_code: In(roleCodes),
|
|
47
75
|
appcode,
|
|
48
|
-
level_type: levelType,
|
|
49
76
|
},
|
|
50
77
|
});
|
|
51
78
|
|
|
@@ -58,6 +85,7 @@ export class ModuleAccessRepository {
|
|
|
58
85
|
action: access.action_type,
|
|
59
86
|
access: access.access_flag,
|
|
60
87
|
code: access.module_code,
|
|
88
|
+
level_type: access.level_type,
|
|
61
89
|
})),
|
|
62
90
|
}));
|
|
63
91
|
}
|
|
@@ -65,54 +93,62 @@ export class ModuleAccessRepository {
|
|
|
65
93
|
async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
|
|
66
94
|
const mainModules =
|
|
67
95
|
mainModIds.length === 1 && mainModIds[0] === '-1'
|
|
68
|
-
? await this.moduleRepo.find({
|
|
96
|
+
? await this.moduleRepo.find({
|
|
97
|
+
where: { module_level: 'MAINMOD', appcode },
|
|
98
|
+
})
|
|
69
99
|
: await this.moduleRepo.find({
|
|
70
100
|
where: { id: In(mainModIds), module_level: 'MAINMOD', appcode },
|
|
71
101
|
});
|
|
72
|
-
|
|
102
|
+
|
|
73
103
|
if (!mainModules.length) return {};
|
|
74
|
-
|
|
104
|
+
|
|
75
105
|
const wbsCodes = mainModules.map((mod) => mod.wbs_code);
|
|
76
|
-
|
|
106
|
+
|
|
77
107
|
const allModules = await this.moduleRepo
|
|
78
108
|
.createQueryBuilder('module')
|
|
79
109
|
.where(
|
|
80
|
-
wbsCodes
|
|
110
|
+
wbsCodes
|
|
111
|
+
.map((code) => `module.wbs_code LIKE :code${code}`)
|
|
112
|
+
.join(' OR '),
|
|
81
113
|
Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
|
|
82
114
|
)
|
|
83
115
|
.andWhere('module.appcode = :appcode', { appcode })
|
|
84
116
|
.getMany();
|
|
85
|
-
|
|
117
|
+
|
|
86
118
|
const moduleCodes = allModules.map((m) => m.module_code);
|
|
87
|
-
|
|
119
|
+
|
|
88
120
|
const allActions = await this.moduleActionRepo.find({
|
|
89
121
|
where: { module_code: In(moduleCodes) },
|
|
90
122
|
});
|
|
91
|
-
|
|
123
|
+
|
|
92
124
|
// Map actions by module_code with full permission object
|
|
93
|
-
const actionMap = allActions.reduce(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
action
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
const actionMap = allActions.reduce(
|
|
126
|
+
(acc, action) => {
|
|
127
|
+
if (!acc[action.module_code]) acc[action.module_code] = [];
|
|
128
|
+
acc[action.module_code].push({
|
|
129
|
+
action: action.action_type,
|
|
130
|
+
name: action.action_name,
|
|
131
|
+
// You can also include action_type here if needed
|
|
132
|
+
});
|
|
133
|
+
return acc;
|
|
134
|
+
},
|
|
135
|
+
{} as Record<string, { action: string; name: string }[]>,
|
|
136
|
+
);
|
|
137
|
+
|
|
103
138
|
const levelsToReturn = levelType === 'ORG' ? ['ORG', 'SCH'] : ['SCH'];
|
|
104
|
-
|
|
139
|
+
|
|
105
140
|
const groupedByLevel: Record<string, any[]> = {};
|
|
106
|
-
|
|
141
|
+
|
|
107
142
|
for (const lvl of levelsToReturn) {
|
|
108
143
|
const filteredModules = allModules.filter((m) => m.level_type === lvl);
|
|
109
|
-
|
|
144
|
+
|
|
110
145
|
const buildHierarchy = (parentWbs: string): any[] =>
|
|
111
146
|
filteredModules
|
|
112
147
|
.filter(
|
|
113
148
|
(mod) =>
|
|
114
149
|
mod.wbs_code.startsWith(`${parentWbs}.`) &&
|
|
115
|
-
mod.wbs_code.split('.').length ===
|
|
150
|
+
mod.wbs_code.split('.').length ===
|
|
151
|
+
parentWbs.split('.').length + 1,
|
|
116
152
|
)
|
|
117
153
|
.map((mod) => ({
|
|
118
154
|
name: mod.name,
|
|
@@ -120,7 +156,7 @@ export class ModuleAccessRepository {
|
|
|
120
156
|
permission: actionMap[mod.module_code] || [],
|
|
121
157
|
submod: buildHierarchy(mod.wbs_code),
|
|
122
158
|
}));
|
|
123
|
-
|
|
159
|
+
|
|
124
160
|
const levelModules = mainModules
|
|
125
161
|
.filter((mod) => mod.level_type === lvl)
|
|
126
162
|
.map((mod) => ({
|
|
@@ -129,14 +165,13 @@ export class ModuleAccessRepository {
|
|
|
129
165
|
permission: actionMap[mod.module_code] || [],
|
|
130
166
|
submod: buildHierarchy(mod.wbs_code),
|
|
131
167
|
}));
|
|
132
|
-
|
|
168
|
+
|
|
133
169
|
if (levelModules.length) {
|
|
134
170
|
groupedByLevel[lvl] = levelModules;
|
|
135
171
|
}
|
|
136
172
|
}
|
|
137
173
|
return groupedByLevel;
|
|
138
174
|
}
|
|
139
|
-
|
|
140
175
|
|
|
141
176
|
async updateModuleAccess(
|
|
142
177
|
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[]) {
|