rez_core 1.0.65 → 1.0.66

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": "1.0.65",
3
+ "version": "1.0.66",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,14 +1,17 @@
1
- import { Body, Controller, Get, Inject, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
1
+ import { BadRequestException, Body, Controller, Get, Inject, Param, Post, Query, Req, Request, 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
4
  import { ENTITYTYPE_USER } from '../../../constant/global.constant';
5
5
  import { UserService } from '../../user/service/user.service';
6
6
  import { UserData } from '../../user/entity/user.entity';
7
+ import { MenuRepository } from '../repository/menu.repository';
7
8
 
8
9
  @Controller('module-access')
9
10
  @UseGuards(JwtAuthGuard)
10
11
  export class ModuleAccessController {
11
- constructor(private readonly moduleAccessService: ModuleAccessService) {}
12
+ constructor(private readonly moduleAccessService: ModuleAccessService,
13
+ private readonly menuRepository: MenuRepository
14
+ ) {}
12
15
 
13
16
  @Get('roles')
14
17
  async getRoles() {
@@ -37,6 +40,20 @@ export class ModuleAccessController {
37
40
  return this.moduleAccessService.updateModuleAccess(moduleAccessData);
38
41
  }
39
42
 
43
+ // src/module/module-access/controller/module-access.controller.ts
44
+
45
+ @Get('ui-config')
46
+ async getModuleUIConfig(@Query('module_code') moduleCode: string, @Request() req) {
47
+ const userId = req.user.userId;
48
+
49
+ const roles = await this.menuRepository.getUserRoles(userId); // returns ['1', '4']
50
+
51
+ if (!roles || roles.length === 0) {
52
+ throw new BadRequestException('User has no roles');
53
+ }
54
+
55
+ return this.moduleAccessService.getModuleUIConfig(moduleCode, roles.map(id => Number(id)));
56
+ }
40
57
 
41
58
 
42
59
 
@@ -28,4 +28,14 @@ export class ModuleData {
28
28
 
29
29
  @Column({ type: 'int', nullable: true })
30
30
  ui_visible: number;
31
+
32
+ @Column({ type: 'varchar', length: 100, nullable: true })
33
+ entity_type: string;
34
+
35
+ @Column({ type: 'varchar', length: 100, nullable: true })
36
+ title: string;
37
+
38
+ @Column({ type: 'json', nullable: true })
39
+ ui_config: JSON;
40
+
31
41
  }
@@ -141,4 +141,41 @@ export class ModuleAccessRepository {
141
141
  }
142
142
 
143
143
 
144
+ // src/module/module-access/repository/module-access.repository.ts
145
+
146
+ async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
147
+ const module = await this.moduleRepo.findOne({
148
+ where: { module_code: moduleCode },
149
+ });
150
+
151
+ if (!module) {
152
+ throw new BadRequestException('Module not found');
153
+ }
154
+
155
+ const roles = await this.roleRepo.find({
156
+ where: { id: In(roleIds) },
157
+ });
158
+
159
+ const roleCodes = roles.map(role => role.code);
160
+
161
+ const actions = await this.moduleAccessRepo.find({
162
+ where: {
163
+ module_code: moduleCode,
164
+ role_code: In(roleCodes),
165
+ access_flag: 1,
166
+ },
167
+ });
168
+
169
+ const uniqueActions = [...new Set(actions.map(a => a.action_type))];
170
+
171
+ return {
172
+ entity_type: module.entity_type,
173
+ title: module.title,
174
+ ui_config: module.ui_config || {},
175
+ action: uniqueActions,
176
+ };
177
+ }
178
+
179
+
180
+
144
181
  }
@@ -46,5 +46,12 @@ export class ModuleAccessService {
46
46
  }
47
47
  }
48
48
 
49
+ // src/module/module-access/service/module-access.service.ts
50
+
51
+ async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
52
+ return this.moduleAccessRepository.getModuleUIConfig(moduleCode, roleIds);
53
+ }
54
+
55
+
49
56
 
50
57
  }