rez_core 2.0.86 → 2.0.88

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.
Files changed (34) hide show
  1. package/dist/module/layout_preference/service/layout_preference.service.js +1 -2
  2. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  3. package/dist/module/module/controller/module-access.controller.d.ts +2 -10
  4. package/dist/module/module/controller/module-access.controller.js +12 -10
  5. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  6. package/dist/module/module/entity/module-access.entity.d.ts +1 -0
  7. package/dist/module/module/entity/module-access.entity.js +4 -0
  8. package/dist/module/module/entity/module-access.entity.js.map +1 -1
  9. package/dist/module/module/entity/module.entity.d.ts +1 -0
  10. package/dist/module/module/entity/module.entity.js +4 -0
  11. package/dist/module/module/entity/module.entity.js.map +1 -1
  12. package/dist/module/module/repository/menu.repository.js +9 -4
  13. package/dist/module/module/repository/menu.repository.js.map +1 -1
  14. package/dist/module/module/repository/module-access.repository.d.ts +3 -10
  15. package/dist/module/module/repository/module-access.repository.js +51 -61
  16. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  17. package/dist/module/module/service/module-access.service.d.ts +13 -12
  18. package/dist/module/module/service/module-access.service.js +12 -6
  19. package/dist/module/module/service/module-access.service.js.map +1 -1
  20. package/dist/module/user/service/user-session.service.js +0 -1
  21. package/dist/module/user/service/user-session.service.js.map +1 -1
  22. package/dist/module/user/service/user.service.js +0 -2
  23. package/dist/module/user/service/user.service.js.map +1 -1
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/package.json +2 -1
  26. package/src/module/layout_preference/service/layout_preference.service.ts +4 -3
  27. package/src/module/module/controller/module-access.controller.ts +22 -7
  28. package/src/module/module/entity/module-access.entity.ts +3 -0
  29. package/src/module/module/entity/module.entity.ts +4 -0
  30. package/src/module/module/repository/menu.repository.ts +18 -8
  31. package/src/module/module/repository/module-access.repository.ts +67 -72
  32. package/src/module/module/service/module-access.service.ts +32 -9
  33. package/src/module/user/service/user-session.service.ts +0 -1
  34. package/src/module/user/service/user.service.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.0.86",
3
+ "version": "2.0.88",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -89,6 +89,7 @@
89
89
  "js",
90
90
  "json",
91
91
  "ts"
92
+
92
93
  ],
93
94
  "rootDir": "src",
94
95
  "testRegex": ".*\\.spec\\.ts$",
@@ -25,15 +25,16 @@ export class LayoutPreferenceService extends EntityServiceImpl {
25
25
  );
26
26
 
27
27
  if (existingLayoutPreference) {
28
- console.log('existing preference');
29
-
30
28
  return await super.updateEntity(
31
29
  { ...entityData, id: existingLayoutPreference.id },
32
30
  loggedInUser,
33
31
  );
34
32
  }
35
33
 
36
- return await super.createEntity(entityData, loggedInUser);
34
+ return await super.createEntity(
35
+ { ...entityData, user_id: userId } as any,
36
+ loggedInUser,
37
+ );
37
38
  }
38
39
 
39
40
  async getLayoutPreferenceByUserID(user_id, mapped_entity_type) {
@@ -43,18 +43,33 @@ export class ModuleAccessController {
43
43
  }
44
44
 
45
45
  @Get('access-listing')
46
- async getAccessListing(@Query('roles') roleIds: string, @Request() req) {
46
+ async getAccessListing(
47
+ @Query('roles') roleIds: string,
48
+ @Query('appcode') queryAppcode: string,
49
+ @Request() req,
50
+ ) {
47
51
  const roleIdArray = roleIds.split(',').map(Number);
48
- const appcode = req.user.userData.appcode;
49
- return this.moduleAccessService.getAccessListing(roleIdArray, appcode);
52
+ const appcode = queryAppcode || req.user.userData.appcode;
53
+ return this.moduleAccessService.getAccessListing(roleIdArray, appcode,"");
50
54
  }
51
-
55
+
52
56
  @Get('menu-listing')
53
- async getMenuListing(@Query('mainmod') mainModIds: string, @Request() req) {
57
+ async getMenuListing(
58
+ @Query('mainmod') mainModIds: string,
59
+ @Query('appcode') appcode: string,
60
+ @Request() req,
61
+ ) {
54
62
  const mainModArray = mainModIds.split(',').map(String);
55
- const appcode = req.user.userData.appcode;
56
- return this.moduleAccessService.getMenuListing(mainModArray, appcode);
63
+ const { level_type} = req.user.userData;
64
+
65
+ return this.moduleAccessService.getMenuListing(
66
+ mainModArray,
67
+ appcode,
68
+ level_type
69
+ );
57
70
  }
71
+
72
+
58
73
 
59
74
  @Post('update')
60
75
  async updateModuleAccess(@Body() moduleAccessData: any[], @Request() req) {
@@ -17,6 +17,9 @@ export class ModuleAccess {
17
17
  @Column({type: 'varchar', length: 100, nullable: true })
18
18
  action_type: string;
19
19
 
20
+ @Column({type: 'varchar', length: 100, nullable: true })
21
+ level_type: string;
22
+
20
23
  @Column({type: 'varchar', length: 100, nullable: true})
21
24
  appcode: string;
22
25
  }
@@ -32,6 +32,7 @@ export class ModuleData {
32
32
  @Column({ type: 'varchar', length: 100, nullable: true })
33
33
  entity_type: string;
34
34
 
35
+
35
36
  @Column({ type: 'varchar', length: 100, nullable: true })
36
37
  title: string;
37
38
 
@@ -46,4 +47,7 @@ export class ModuleData {
46
47
 
47
48
  @Column({ type: 'varchar', length: 100, nullable: true })
48
49
  type: string;
50
+
51
+ @Column({ type: 'varchar', length: 100, nullable: true })
52
+ level_type: string;
49
53
  }
@@ -34,10 +34,10 @@ export class MenuRepository extends Repository<MenuData> {
34
34
  .select('role.code')
35
35
  .where('role.id IN (:...roleIds)', { roleIds })
36
36
  .getMany();
37
-
37
+
38
38
  const codes = roleCodes.map((role) => role.code);
39
39
  if (codes.length === 0) return [];
40
-
40
+
41
41
  const modules = await this.dataSource
42
42
  .getRepository(ModuleAccess)
43
43
  .createQueryBuilder('moduleAccess')
@@ -46,18 +46,28 @@ export class MenuRepository extends Repository<MenuData> {
46
46
  .andWhere('moduleAccess.access_flag > 0')
47
47
  .andWhere('LOWER(moduleAccess.appcode) = LOWER(:appCode)', { appCode })
48
48
  .getMany();
49
-
50
- return modules.map((module) => module.module_code);
49
+
50
+ return Array.from(new Set(modules.map((module) => module.module_code)));
51
51
  }
52
+
52
53
 
53
54
  /**
54
55
  * ✅ FIXED: Use this.createQueryBuilder() instead of this.menuData.createQueryBuilder()
55
56
  */
56
57
  async getMenuItems(moduleCodes: string[], appcode: string, levelType: string) {
57
- return await this.menuData.createQueryBuilder('menu')
58
- .leftJoin('cr_module', 'module', 'menu.module_code = module.module_code')
58
+ return await this.menuData
59
+ .createQueryBuilder('menu')
60
+ .leftJoin(
61
+ 'cr_module',
62
+ 'module',
63
+ `
64
+ menu.module_code = module.module_code
65
+ AND LOWER(menu.appcode) = LOWER(module.appcode)
66
+ AND menu.level_type = module.level_type
67
+ `
68
+ )
59
69
  .where('menu.module_code IN (:...moduleCodes)', { moduleCodes })
60
- .andWhere('LOWER(module.appcode) = LOWER(:appcode)', { appcode })
70
+ .andWhere('LOWER(menu.appcode) = LOWER(:appcode)', { appcode })
61
71
  .andWhere('menu.level_type = :levelType', { levelType })
62
72
  .select([
63
73
  'menu.*',
@@ -69,7 +79,7 @@ export class MenuRepository extends Repository<MenuData> {
69
79
  ])
70
80
  .getRawMany();
71
81
  }
72
-
82
+
73
83
 
74
84
  async resolveUserRoles(
75
85
  userId: number,
@@ -5,50 +5,48 @@ 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';
7
7
  import { ModuleData } from '../entity/module.entity';
8
- import { ClockIDGenService } from 'src/utils/service/clockIDGenUtil.service';
9
- import { UserData } from 'src/module/user/entity/user.entity';
10
8
 
11
9
  @Injectable()
12
10
  export class ModuleAccessRepository {
13
11
  constructor(
14
12
  @InjectRepository(Role)
15
13
  private readonly roleRepo: Repository<Role>,
14
+
16
15
  @InjectRepository(ModuleData)
17
16
  private readonly moduleRepo: Repository<ModuleData>,
17
+
18
18
  @InjectRepository(ModuleAccess)
19
19
  private readonly moduleAccessRepo: Repository<ModuleAccess>,
20
+
20
21
  @InjectRepository(ModuleAction)
21
22
  private readonly moduleActionRepo: Repository<ModuleAction>,
22
23
  ) {}
23
24
 
24
25
  async getRoles({ appcode }: { appcode: string }) {
25
- const roles = await this.roleRepo.find({
26
- where: { appcode: appcode },
27
- });
28
- return roles.map((role) => ({
29
- label: role.name,
30
- value: role.id,
31
- }));
26
+ const roles = await this.roleRepo.find({ where: { appcode } });
27
+ return roles.map((role) => ({ label: role.name, value: role.id }));
32
28
  }
33
29
 
34
30
  async getModules({ appcode }: { appcode: string }) {
35
31
  const modules = await this.moduleRepo.find({
36
- where: { module_level: 'MAINMOD', appcode: appcode },
32
+ where: { module_level: 'MAINMOD', appcode },
37
33
  });
38
- return modules.map((mod) => ({
39
- label: mod.name,
40
- value: mod.id,
41
- }));
34
+ return modules.map((mod) => ({ label: mod.name, value: mod.id }));
42
35
  }
43
36
 
44
- async getAccessListing(roleIds: number[], appcode: string) {
37
+ async getAccessListing(roleIds: number[], appcode: string, levelType: string) {
45
38
  const roles = await this.roleRepo.find({
46
- where: { id: In(roleIds), appcode: appcode },
39
+ where: { id: In(roleIds), appcode },
47
40
  });
41
+
48
42
  const roleCodes = roles.map((role) => role.code);
49
43
 
50
44
  const moduleAccesses = await this.moduleAccessRepo.find({
51
- where: { role_code: In(roleCodes), appcode: appcode },
45
+ where: {
46
+ role_code: In(roleCodes),
47
+ appcode,
48
+ level_type: levelType,
49
+ },
52
50
  });
53
51
 
54
52
  return roles.map((role) => ({
@@ -64,68 +62,67 @@ export class ModuleAccessRepository {
64
62
  }));
65
63
  }
66
64
 
67
- async getMenuListing(mainModIds: string[], appcode: string) {
65
+
66
+ async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
68
67
  const mainModules =
69
68
  mainModIds.length === 1 && mainModIds[0] === '-1'
70
- ? await this.moduleRepo.find({
71
- where: { module_level: 'MAINMOD', appcode: appcode },
72
- })
69
+ ? await this.moduleRepo.find({ where: { module_level: 'MAINMOD', appcode } })
73
70
  : await this.moduleRepo.find({
74
- where: {
75
- id: In(mainModIds),
76
- module_level: 'MAINMOD',
77
- appcode: appcode,
78
- },
71
+ where: { id: In(mainModIds), module_level: 'MAINMOD', appcode },
79
72
  });
80
-
81
- if (!mainModules.length) return [];
82
-
73
+
74
+ if (!mainModules.length) return {};
75
+
83
76
  const wbsCodes = mainModules.map((mod) => mod.wbs_code);
84
-
85
- const modules = await this.moduleRepo
77
+
78
+ const allModules = await this.moduleRepo
86
79
  .createQueryBuilder('module')
87
80
  .where(
88
- wbsCodes
89
- .map((code) => `module.wbs_code LIKE :code${code}`)
90
- .join(' OR '),
81
+ wbsCodes.map((code) => `module.wbs_code LIKE :code${code}`).join(' OR '),
91
82
  Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
92
83
  )
84
+ .andWhere('module.appcode = :appcode', { appcode })
93
85
  .getMany();
94
-
95
- const moduleActions = await this.moduleActionRepo.find();
96
-
97
- const buildHierarchy = (parentWbs: string): any[] =>
98
- modules
99
- .filter(
100
- (mod) =>
101
- mod.wbs_code.startsWith(`${parentWbs}.`) &&
102
- mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
103
- )
86
+
87
+ const levelsToReturn = levelType === 'ORG' ? ['ORG', 'SCH'] : ['SCH'];
88
+
89
+ const groupedByLevel: Record<string, any[]> = {};
90
+
91
+ for (const lvl of levelsToReturn) {
92
+ const filteredModules = allModules.filter((m) => m.level_type === lvl);
93
+
94
+ const buildHierarchy = (parentWbs: string): any[] =>
95
+ filteredModules
96
+ .filter(
97
+ (mod) =>
98
+ mod.wbs_code.startsWith(`${parentWbs}.`) &&
99
+ mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
100
+ )
101
+ .map((mod) => ({
102
+ name: mod.name,
103
+ code: mod.module_code,
104
+ permission: [], // No actions, since you're not using role filtering
105
+ submod: buildHierarchy(mod.wbs_code),
106
+ }));
107
+
108
+ const levelModules = mainModules
109
+ .filter((mod) => mod.level_type === lvl)
104
110
  .map((mod) => ({
105
111
  name: mod.name,
106
112
  code: mod.module_code,
107
- permission: moduleActions
108
- .filter((action) => action.module_code === mod.module_code)
109
- .map((action) => ({
110
- action: action.action_type,
111
- name: action.action_type,
112
- })),
113
+ permission: [],
113
114
  submod: buildHierarchy(mod.wbs_code),
114
115
  }));
115
-
116
- return mainModules.map((mod) => ({
117
- name: mod.name,
118
- code: mod.module_code,
119
- permission: moduleActions
120
- .filter((action) => action.module_code === mod.module_code)
121
- .map((action) => ({
122
- action: action.action_type,
123
- name: action.action_type,
124
- })),
125
- submod: buildHierarchy(mod.wbs_code),
126
- }));
116
+
117
+ if (levelModules.length) {
118
+ groupedByLevel[lvl] = levelModules;
119
+ }
120
+ }
121
+
122
+ return groupedByLevel;
127
123
  }
128
124
 
125
+
129
126
  async updateModuleAccess(
130
127
  accessList: {
131
128
  role_code: string;
@@ -133,6 +130,7 @@ export class ModuleAccessRepository {
133
130
  action_type: string;
134
131
  access_flag: number;
135
132
  appcode: string;
133
+ level_type: string;
136
134
  }[],
137
135
  appcode: string,
138
136
  ): Promise<boolean> {
@@ -144,6 +142,7 @@ export class ModuleAccessRepository {
144
142
  module_code: access.module_code,
145
143
  action_type: access.action_type,
146
144
  appcode: access.appcode || appcode,
145
+ level_type: access.level_type,
147
146
  },
148
147
  });
149
148
 
@@ -152,7 +151,10 @@ export class ModuleAccessRepository {
152
151
  await this.moduleAccessRepo.save(existing);
153
152
  } else {
154
153
  await this.moduleAccessRepo.save(
155
- this.moduleAccessRepo.create(access),
154
+ this.moduleAccessRepo.create({
155
+ ...access,
156
+ appcode: access.appcode || appcode,
157
+ }),
156
158
  );
157
159
  }
158
160
  }
@@ -163,21 +165,14 @@ export class ModuleAccessRepository {
163
165
  }
164
166
  }
165
167
 
166
- // src/module/module-access/repository/module-access.repository.ts
167
-
168
168
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
169
169
  const module = await this.moduleRepo.findOne({
170
170
  where: { module_code: moduleCode },
171
171
  });
172
172
 
173
- if (!module) {
174
- throw new BadRequestException('Module not found');
175
- }
176
-
177
- const roles = await this.roleRepo.find({
178
- where: { id: In(roleIds) },
179
- });
173
+ if (!module) throw new BadRequestException('Module not found');
180
174
 
175
+ const roles = await this.roleRepo.find({ where: { id: In(roleIds) } });
181
176
  const roleCodes = roles.map((role) => role.code);
182
177
 
183
178
  const actions = await this.moduleAccessRepo.find({
@@ -6,11 +6,13 @@ import { ENTITYTYPE_ROLE } from '../../../constant/global.constant';
6
6
  import { Role } from '../../user/entity/role.entity';
7
7
  import { EntityManager } from 'typeorm';
8
8
  import { UserData } from 'src/module/user/entity/user.entity';
9
+ import { MenuRepository } from '../repository/menu.repository';
9
10
 
10
11
  @Injectable()
11
12
  export class ModuleAccessService {
12
13
  constructor(
13
14
  private readonly moduleAccessRepository: ModuleAccessRepository,
15
+ private readonly menuRepository: MenuRepository,
14
16
  ) {}
15
17
 
16
18
  async getRoles({ appcode }: { appcode: string }) {
@@ -22,28 +24,48 @@ export class ModuleAccessService {
22
24
  appcode,
23
25
  });
24
26
  }
25
-
26
- async getAccessListing(roleIds: number[], appcode: string) {
27
- return this.moduleAccessRepository.getAccessListing(roleIds, appcode);
27
+ async getAccessListing(
28
+ roleIds: number[],
29
+ appcode: string,
30
+ levelType: string,
31
+ ) {
32
+ return this.moduleAccessRepository.getAccessListing(roleIds, appcode, levelType);
28
33
  }
29
-
30
- async getMenuListing(mainModIds: string[], appcode: string) {
31
- return this.moduleAccessRepository.getMenuListing(mainModIds, appcode);
34
+
35
+ async getMenuListing(
36
+ mainModIds: string[],
37
+ appcode: string,
38
+ levelType: string,
39
+ ): Promise<Record<string, any[]>> {
40
+ if (!appcode) {
41
+ throw new BadRequestException('Appcode is required');
42
+ }
43
+
44
+ return this.moduleAccessRepository.getAllModulesByLevel(mainModIds, appcode, levelType);
32
45
  }
46
+
47
+
33
48
 
34
49
  async updateModuleAccess(
35
- moduleAccessData: any[],
50
+ moduleAccessData: {
51
+ role_code: string;
52
+ module_code: string;
53
+ action_type: string;
54
+ access_flag: number;
55
+ appcode: string;
56
+ level_type: string;
57
+ }[],
36
58
  appcode: string,
37
59
  ): Promise<{ success: boolean; msg: string }> {
38
60
  if (!moduleAccessData || moduleAccessData.length === 0) {
39
61
  return { success: false, msg: 'No data provided' };
40
62
  }
41
-
63
+
42
64
  const result = await this.moduleAccessRepository.updateModuleAccess(
43
65
  moduleAccessData,
44
66
  appcode,
45
67
  );
46
-
68
+
47
69
  if (result) {
48
70
  return { success: true, msg: 'Module access updated successfully' };
49
71
  } else {
@@ -51,6 +73,7 @@ export class ModuleAccessService {
51
73
  }
52
74
  }
53
75
 
76
+
54
77
  // src/module/module-access/service/module-access.service.ts
55
78
 
56
79
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
@@ -74,7 +74,6 @@ export class UserSessionService {
74
74
  level_type: string;
75
75
  level_id: string;
76
76
  }> {
77
- console.log(currentUser, data);
78
77
  let payload;
79
78
 
80
79
  payload = {
@@ -113,7 +113,6 @@ export class UserService extends EntityServiceImpl {
113
113
  if (insertPromises.length > 0) {
114
114
  await Promise.all(insertPromises);
115
115
  }
116
- console.log('Access levels added successfully');
117
116
  } catch (error) {
118
117
  console.error('Error adding access levels:', error);
119
118
  throw new BadRequestException('Failed to add access levels');
@@ -216,7 +215,6 @@ export class UserService extends EntityServiceImpl {
216
215
 
217
216
  try {
218
217
  await Promise.all(insertPromises);
219
- console.log('Access levels updated successfully');
220
218
  } catch (error) {
221
219
  console.error('Error updating access levels:', error);
222
220
  throw new BadRequestException('Failed to update access levels');