rez_core 2.1.1 → 2.1.2
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/master/service/master.service.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.d.ts +1 -10
- package/dist/module/module/controller/module-access.controller.js +3 -1
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +1 -10
- package/dist/module/module/repository/module-access.repository.js +30 -5
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +1 -10
- package/dist/module/module/service/module-access.service.js +2 -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/master/service/master.service.ts +0 -1
- package/src/module/module/controller/module-access.controller.ts +3 -1
- package/src/module/module/repository/module-access.repository.ts +42 -12
- package/src/module/module/service/module-access.service.ts +2 -0
package/package.json
CHANGED
|
@@ -45,7 +45,9 @@ export class ModuleAccessController {
|
|
|
45
45
|
) {
|
|
46
46
|
const roleIdArray = roleIds.split(',').map(Number);
|
|
47
47
|
const appcode = queryAppcode || req.user.userData.appcode;
|
|
48
|
-
|
|
48
|
+
const level_type = req.user.userData.appcode;
|
|
49
|
+
const level_id = req.user.userData.appcode;
|
|
50
|
+
return this.moduleAccessService.getAccessListing(roleIdArray, appcode, level_type, level_id);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
@Get('menu-listing')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
2
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { In, Repository } from 'typeorm';
|
|
3
|
+
import { In, Not, Repository } from 'typeorm';
|
|
4
4
|
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';
|
|
@@ -23,6 +23,7 @@ export class ModuleAccessRepository {
|
|
|
23
23
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
async getRoles({
|
|
27
28
|
appcode,
|
|
28
29
|
level_type,
|
|
@@ -32,18 +33,21 @@ export class ModuleAccessRepository {
|
|
|
32
33
|
level_type?: string;
|
|
33
34
|
level_id?: number;
|
|
34
35
|
}) {
|
|
35
|
-
const where: any = {
|
|
36
|
+
const where: any = {
|
|
37
|
+
appcode,
|
|
38
|
+
is_factory: Not(1), // Exclude factory roles
|
|
39
|
+
};
|
|
40
|
+
|
|
36
41
|
if (level_type) where.level_type = level_type;
|
|
37
42
|
if (level_id !== undefined) where.level_id = String(level_id);
|
|
38
|
-
|
|
43
|
+
|
|
39
44
|
const roles = await this.roleRepo.find({ where });
|
|
40
|
-
|
|
45
|
+
|
|
41
46
|
return roles.map((role) => ({
|
|
42
47
|
label: role.name,
|
|
43
48
|
value: role.id,
|
|
44
49
|
}));
|
|
45
50
|
}
|
|
46
|
-
|
|
47
51
|
async getModules({ appcode }: { appcode: string }) {
|
|
48
52
|
const modules = await this.moduleRepo.find({
|
|
49
53
|
where: { module_level: 'MAINMOD', appcode },
|
|
@@ -59,23 +63,48 @@ export class ModuleAccessRepository {
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
async getAccessListing(
|
|
62
|
-
roleIds: number[],
|
|
66
|
+
roleIds: (number | string)[],
|
|
63
67
|
appcode: string,
|
|
64
68
|
levelType: string,
|
|
69
|
+
levelId?: number, // add levelId as input so we can fetch roles based on it
|
|
65
70
|
) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
let roles;
|
|
72
|
+
|
|
73
|
+
if (roleIds.length === 1 && roleIds[0] === '-1') {
|
|
74
|
+
// Internally call getRoles
|
|
75
|
+
const fetchedRoles = await this.getRoles({
|
|
76
|
+
appcode,
|
|
77
|
+
level_type: levelType,
|
|
78
|
+
level_id: levelId,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const fetchedRoleIds = fetchedRoles.map((r) => r.value);
|
|
82
|
+
roles = await this.roleRepo.find({
|
|
83
|
+
where: {
|
|
84
|
+
id: In(fetchedRoleIds),
|
|
85
|
+
appcode,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
roles = await this.roleRepo.find({
|
|
90
|
+
where: {
|
|
91
|
+
id: In(roleIds.map((id) => Number(id))),
|
|
92
|
+
appcode,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!roles.length) return [];
|
|
98
|
+
|
|
70
99
|
const roleCodes = roles.map((role) => role.code);
|
|
71
|
-
|
|
100
|
+
|
|
72
101
|
const moduleAccesses = await this.moduleAccessRepo.find({
|
|
73
102
|
where: {
|
|
74
103
|
role_code: In(roleCodes),
|
|
75
104
|
appcode,
|
|
76
105
|
},
|
|
77
106
|
});
|
|
78
|
-
|
|
107
|
+
|
|
79
108
|
return roles.map((role) => ({
|
|
80
109
|
role_code: role.code,
|
|
81
110
|
name: role.name,
|
|
@@ -89,6 +118,7 @@ export class ModuleAccessRepository {
|
|
|
89
118
|
})),
|
|
90
119
|
}));
|
|
91
120
|
}
|
|
121
|
+
|
|
92
122
|
|
|
93
123
|
async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
|
|
94
124
|
const mainModules =
|
|
@@ -40,11 +40,13 @@ export class ModuleAccessService {
|
|
|
40
40
|
roleIds: number[],
|
|
41
41
|
appcode: string,
|
|
42
42
|
levelType: string,
|
|
43
|
+
level_id?: number,
|
|
43
44
|
) {
|
|
44
45
|
return this.moduleAccessRepository.getAccessListing(
|
|
45
46
|
roleIds,
|
|
46
47
|
appcode,
|
|
47
48
|
levelType,
|
|
49
|
+
level_id
|
|
48
50
|
);
|
|
49
51
|
}
|
|
50
52
|
|