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