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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -472,7 +472,6 @@ export class MasterService {
472
472
  row.entity_type = entityType;
473
473
  row.organization_id = loggedInUser.organization_id;
474
474
  row.status = 'ACTIVE';
475
-
476
475
  let errors = [];
477
476
  if (existing) {
478
477
  if (duplicateHandling === 'skip_duplicates') continue;
@@ -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
- return this.moduleAccessService.getAccessListing(roleIdArray, appcode, '');
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 = { appcode };
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
- const roles = await this.roleRepo.find({
67
- where: { id: In(roleIds), appcode },
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