rez_core 2.0.28 → 2.0.29
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 -3
- package/dist/module/module/controller/module-access.controller.js +5 -5
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/service/menu.service.d.ts +1 -0
- package/dist/module/module/service/menu.service.js +3 -0
- package/dist/module/module/service/menu.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 +3 -2
- package/src/module/module/service/menu.service.ts +15 -5
package/package.json
CHANGED
|
@@ -17,13 +17,14 @@ import { ENTITYTYPE_USER } from '../../../constant/global.constant';
|
|
|
17
17
|
import { UserService } from '../../user/service/user.service';
|
|
18
18
|
import { UserData } from '../../user/entity/user.entity';
|
|
19
19
|
import { MenuRepository } from '../repository/menu.repository';
|
|
20
|
+
import { MenuService } from '../service/menu.service';
|
|
20
21
|
|
|
21
22
|
@Controller('module-access')
|
|
22
23
|
@UseGuards(JwtAuthGuard)
|
|
23
24
|
export class ModuleAccessController {
|
|
24
25
|
constructor(
|
|
25
26
|
private readonly moduleAccessService: ModuleAccessService,
|
|
26
|
-
private readonly
|
|
27
|
+
private readonly menuService: MenuService,
|
|
27
28
|
) {}
|
|
28
29
|
|
|
29
30
|
@Get('roles')
|
|
@@ -73,7 +74,7 @@ export class ModuleAccessController {
|
|
|
73
74
|
) {
|
|
74
75
|
const userId = req.user.userData?.id;
|
|
75
76
|
const appcode = req.user.userData?.appcode;
|
|
76
|
-
const roles = await this.
|
|
77
|
+
const roles = await this.menuService.getUserRoles(userId, appcode); // returns ['1', '4']
|
|
77
78
|
|
|
78
79
|
if (!roles || roles.length === 0) {
|
|
79
80
|
throw new BadRequestException('User has no roles');
|
|
@@ -9,22 +9,27 @@ export class MenuService {
|
|
|
9
9
|
/**
|
|
10
10
|
* Fetch and construct menu hierarchy for a given user.
|
|
11
11
|
*/
|
|
12
|
-
async getUserMenu(userId: number,appcode:string): Promise<{ menu: any[] }> {
|
|
12
|
+
async getUserMenu(userId: number, appcode: string): Promise<{ menu: any[] }> {
|
|
13
13
|
// Step 1: Get the roles of the user
|
|
14
|
-
const roleCodes = await this.menuRepository.getUserRoles(userId,appcode);
|
|
14
|
+
const roleCodes = await this.menuRepository.getUserRoles(userId, appcode);
|
|
15
15
|
if (!roleCodes.length) {
|
|
16
16
|
return { menu: [] }; // Return empty menu if user has no roles
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Step 2: Get the modules the user has access to
|
|
20
|
-
const moduleCodes =
|
|
21
|
-
|
|
20
|
+
const moduleCodes = await this.menuRepository.getAccessibleModules(
|
|
21
|
+
roleCodes,
|
|
22
|
+
appcode,
|
|
23
|
+
);
|
|
22
24
|
if (!moduleCodes.length) {
|
|
23
25
|
return { menu: [] }; // Return empty menu if no accessible modules
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// Step 3: Get the menu items based on accessible modules
|
|
27
|
-
const menuItems = await this.menuRepository.getMenuItems(
|
|
29
|
+
const menuItems = await this.menuRepository.getMenuItems(
|
|
30
|
+
moduleCodes,
|
|
31
|
+
appcode,
|
|
32
|
+
);
|
|
28
33
|
|
|
29
34
|
// Step 4: Build hierarchical menu structure
|
|
30
35
|
const menuTree = this.buildMenuHierarchy(menuItems);
|
|
@@ -57,4 +62,9 @@ export class MenuService {
|
|
|
57
62
|
|
|
58
63
|
return rootMenu;
|
|
59
64
|
}
|
|
65
|
+
|
|
66
|
+
// get user roles
|
|
67
|
+
async getUserRoles(userId: number, appcode: string): Promise<any> {
|
|
68
|
+
return this.menuRepository.getUserRoles(userId, appcode);
|
|
69
|
+
}
|
|
60
70
|
}
|