rez_core 2.1.11 → 2.1.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -93,4 +93,27 @@ export class ModuleAccessController {
93
93
  roles.map((id) => Number(id)),
94
94
  );
95
95
  }
96
+
97
+ @Get('user-permissions')
98
+ async getUserPermissions(@Request() req) {
99
+ const userData = req.user.userData;
100
+
101
+ const userId = userData?.id;
102
+ const appcode = userData?.appcode;
103
+ const level_type = userData?.level_type;
104
+ const level_id = userData?.level_id;
105
+
106
+ if (!userId || !appcode || !level_type || !level_id) {
107
+ throw new BadRequestException('Invalid token data');
108
+ }
109
+
110
+ return this.moduleAccessService.getUserPermissions({
111
+ userId,
112
+ appcode,
113
+ level_type,
114
+ level_id,
115
+ });
116
+ }
117
+
118
+
96
119
  }
@@ -284,4 +284,43 @@ export class ModuleAccessRepository {
284
284
  action: uniqueActions,
285
285
  };
286
286
  }
287
+ async getModuleAccessByRoles(roleIds: number[], appcode: string) {
288
+ // Step 1: Get role codes from cr_role
289
+ const roles = await this.roleRepo.find({
290
+ where: {
291
+ id: In(roleIds),
292
+ appcode,
293
+ },
294
+ select: ['id', 'code'],
295
+ });
296
+
297
+ const roleCodes = roles.map((r) => r.code);
298
+ if (!roleCodes.length) return [];
299
+
300
+ // Step 2: Fetch full access data
301
+ const accessRecords = await this.moduleAccessRepo
302
+ .createQueryBuilder('access')
303
+ .select([
304
+ 'access.module_code AS module_code',
305
+ 'access.action_type AS action_type',
306
+ 'access.access_flag AS access_flag',
307
+ 'access.level_type AS level_type',
308
+ 'access.appcode AS appcode',
309
+ ])
310
+ .where('access.role_code IN (:...roleCodes)', { roleCodes })
311
+ .andWhere('access.appcode = :appcode', { appcode })
312
+ .getRawMany();
313
+
314
+ // Step 3: Format output
315
+ return accessRecords.map((record) => ({
316
+ action: record.action_type,
317
+ access: record.access_flag,
318
+ code: record.module_code,
319
+ level_type: record.level_type,
320
+ appcode: record.appcode,
321
+ }));
322
+ }
323
+
324
+
287
325
  }
326
+
@@ -117,7 +117,32 @@ export class ModuleAccessService {
117
117
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
118
118
  return this.moduleAccessRepository.getModuleUIConfig(moduleCode, roleIds);
119
119
  }
120
- }
121
-
122
120
 
123
- //hi
121
+ async getUserPermissions({
122
+ userId,
123
+ appcode,
124
+ level_type,
125
+ level_id,
126
+ }: {
127
+ userId: number;
128
+ appcode: string;
129
+ level_type: string;
130
+ level_id: number;
131
+ }) {
132
+ const roleCodes = await this.menuRepository.resolveUserRoles(
133
+ userId,
134
+ appcode,
135
+ level_type,
136
+ level_id,
137
+ );
138
+
139
+ if (!roleCodes || roleCodes.length === 0) {
140
+ return [];
141
+ }
142
+
143
+ const roleIds = roleCodes.map(Number);
144
+ return this.moduleAccessRepository.getModuleAccessByRoles(roleIds, appcode);
145
+ }
146
+
147
+
148
+ }