rez_core 2.0.0 → 2.0.1

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 (65) hide show
  1. package/dist/module/enterprise/entity/enterprise.entity.d.ts +1 -1
  2. package/dist/module/enterprise/entity/enterprise.entity.js +2 -2
  3. package/dist/module/enterprise/entity/enterprise.entity.js.map +1 -1
  4. package/dist/module/enterprise/entity/organization.entity.d.ts +1 -1
  5. package/dist/module/enterprise/entity/organization.entity.js +2 -2
  6. package/dist/module/enterprise/entity/organization.entity.js.map +1 -1
  7. package/dist/module/filter/entity/saved-filter-master.entity.d.ts +0 -1
  8. package/dist/module/filter/entity/saved-filter-master.entity.js +0 -4
  9. package/dist/module/filter/entity/saved-filter-master.entity.js.map +1 -1
  10. package/dist/module/master/service/master.service.js +31 -15
  11. package/dist/module/master/service/master.service.js.map +1 -1
  12. package/dist/module/meta/entity/entity-table-column.entity.d.ts +0 -1
  13. package/dist/module/meta/entity/entity-table-column.entity.js +0 -4
  14. package/dist/module/meta/entity/entity-table-column.entity.js.map +1 -1
  15. package/dist/module/meta/entity/entity-table.entity.d.ts +0 -1
  16. package/dist/module/meta/entity/entity-table.entity.js +0 -4
  17. package/dist/module/meta/entity/entity-table.entity.js.map +1 -1
  18. package/dist/module/module/controller/menu.controller.js +2 -1
  19. package/dist/module/module/controller/menu.controller.js.map +1 -1
  20. package/dist/module/module/controller/module-access.controller.js +2 -1
  21. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  22. package/dist/module/module/entity/menu.entity.d.ts +1 -0
  23. package/dist/module/module/entity/menu.entity.js +4 -0
  24. package/dist/module/module/entity/menu.entity.js.map +1 -1
  25. package/dist/module/module/entity/module-access.entity.d.ts +1 -1
  26. package/dist/module/module/entity/module-access.entity.js +1 -1
  27. package/dist/module/module/entity/module-access.entity.js.map +1 -1
  28. package/dist/module/module/entity/module.entity.d.ts +1 -0
  29. package/dist/module/module/entity/module.entity.js +4 -0
  30. package/dist/module/module/entity/module.entity.js.map +1 -1
  31. package/dist/module/module/repository/menu.repository.d.ts +3 -3
  32. package/dist/module/module/repository/menu.repository.js +12 -8
  33. package/dist/module/module/repository/menu.repository.js.map +1 -1
  34. package/dist/module/module/repository/module-access.repository.js +1 -1
  35. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  36. package/dist/module/module/service/menu.service.d.ts +1 -1
  37. package/dist/module/module/service/menu.service.js +4 -4
  38. package/dist/module/module/service/menu.service.js.map +1 -1
  39. package/dist/module/user/entity/role.entity.d.ts +0 -1
  40. package/dist/module/user/entity/role.entity.js +0 -4
  41. package/dist/module/user/entity/role.entity.js.map +1 -1
  42. package/dist/module/user/entity/user-role-mapping.entity.d.ts +1 -0
  43. package/dist/module/user/entity/user-role-mapping.entity.js +4 -0
  44. package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
  45. package/dist/module/user/service/role.service.js +2 -2
  46. package/dist/module/user/service/role.service.js.map +1 -1
  47. package/dist/tsconfig.build.tsbuildinfo +1 -1
  48. package/package.json +1 -1
  49. package/src/module/enterprise/entity/enterprise.entity.ts +2 -2
  50. package/src/module/enterprise/entity/organization.entity.ts +2 -2
  51. package/src/module/filter/entity/saved-filter-master.entity.ts +0 -3
  52. package/src/module/master/service/master.service.ts +31 -15
  53. package/src/module/meta/entity/entity-table-column.entity.ts +1 -2
  54. package/src/module/meta/entity/entity-table.entity.ts +0 -2
  55. package/src/module/module/controller/menu.controller.ts +2 -1
  56. package/src/module/module/controller/module-access.controller.ts +2 -2
  57. package/src/module/module/entity/menu.entity.ts +3 -0
  58. package/src/module/module/entity/module-access.entity.ts +1 -1
  59. package/src/module/module/entity/module.entity.ts +3 -0
  60. package/src/module/module/repository/menu.repository.ts +48 -43
  61. package/src/module/module/repository/module-access.repository.ts +1 -1
  62. package/src/module/module/service/menu.service.ts +4 -4
  63. package/src/module/user/entity/role.entity.ts +0 -3
  64. package/src/module/user/entity/user-role-mapping.entity.ts +3 -0
  65. package/src/module/user/service/role.service.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -29,8 +29,8 @@ export class EnterpriseData {
29
29
  @Column({ name: 'modified_date', type: 'datetime', nullable: true })
30
30
  modified_date: Date;
31
31
 
32
- @Column({ name: 'app_code', type: 'varchar', nullable: true, length: 50 })
33
- app_code: string;
32
+ @Column({ name: 'appcode', type: 'varchar', nullable: true, length: 50 })
33
+ appcode: string;
34
34
 
35
35
  @Column({ name: 'app_url_name', type: 'varchar', nullable: true, length: 50 })
36
36
  app_url_name: string;
@@ -11,8 +11,8 @@ export class OrganizationData {
11
11
  @Column({ name: 'code', nullable: true })
12
12
  code: string;
13
13
 
14
- @Column({ name: 'app_code', nullable: true })
15
- appCode: string;
14
+ @Column({ name: 'appcode', nullable: true })
15
+ appcode: string;
16
16
 
17
17
  @Column({ name: 'name', nullable: true })
18
18
  name: string;
@@ -9,9 +9,6 @@ export class SavedFilterMaster extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_SAVEDFILTERMASTER;
10
10
  }
11
11
 
12
- @Column({ length: 50, type: 'varchar', nullable: true })
13
- app_code: string;
14
-
15
12
  @Column({ length: 50, type: 'varchar', nullable: true })
16
13
  mapped_entity_type: string;
17
14
 
@@ -257,17 +257,27 @@ export class MasterService {
257
257
  continue;
258
258
  }
259
259
 
260
+ const existingError = errors.find((e) => e.row === i + 1);
261
+
260
262
  if (refData[0].organization_id !== loggedInUser.organization_id) {
261
- errors.push({
262
- row: i + 1,
263
- errors: [
264
- {
265
- field: attr.name,
266
- message: `Reference entity with code ${row[attr.attribute_key]} does not belong to the organization`,
267
- },
268
- ],
269
- });
270
- continue;
263
+ if (existingError) {
264
+ existingError.errors.push({
265
+ field: attr.name,
266
+ message: `Reference entity not found for code: ${row[attr.attribute_key]} does not belong to the organization`,
267
+ });
268
+ continue;
269
+ } else {
270
+ errors.push({
271
+ row: i + 1,
272
+ errors: [
273
+ {
274
+ field: attr.name,
275
+ message: `Reference entity with code ${row[attr.attribute_key]} does not belong to the organization`,
276
+ },
277
+ ],
278
+ });
279
+ continue;
280
+ }
271
281
  }
272
282
 
273
283
  row[attr.attribute_key] = refData[0].id;
@@ -407,11 +417,17 @@ export class MasterService {
407
417
  entityMaster,
408
418
  );
409
419
 
420
+ const existingError = errors.find((e) => e.row === i + 1);
421
+
410
422
  if (rowErrors?.length > 0) {
411
- errors.push({
412
- row: i + 1,
413
- errors: rowErrors,
414
- });
423
+ if (existingError) {
424
+ existingError.errors.push(...rowErrors);
425
+ } else {
426
+ errors.push({
427
+ row: i + 1,
428
+ errors: rowErrors,
429
+ });
430
+ }
415
431
  }
416
432
  }
417
433
 
@@ -419,7 +435,7 @@ export class MasterService {
419
435
  throw new BadRequestException({
420
436
  status: false,
421
437
  message: `Validation errors found in the uploaded data.`,
422
- details: errors,
438
+ error: errors,
423
439
  });
424
440
  }
425
441
 
@@ -9,8 +9,7 @@ export class EntityTableColumn extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_ENTITYTABLECOLUMN;
10
10
  }
11
11
 
12
- @Column({ name: 'app_code', nullable: true })
13
- app_code: string;
12
+
14
13
 
15
14
  @Column({ name: 'mapped_entity_type', nullable: true })
16
15
  mapped_entity_type: string;
@@ -9,8 +9,6 @@ export class EntityTable extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_ENTITYTABLE;
10
10
  }
11
11
 
12
- @Column({ name: 'app_code', nullable: true })
13
- app_code: string;
14
12
 
15
13
  @Column({ name: 'mapped_entity_type', nullable: true })
16
14
  mapped_entity_type: string;
@@ -10,6 +10,7 @@ export class MenuController {
10
10
  @Get()
11
11
  async getMenu(@Request() req) {
12
12
  const userId = req.user.userId;
13
- return this.menuService.getUserMenu(userId);
13
+ const appcode = req.user.appcode;
14
+ return this.menuService.getUserMenu(userId,appcode);
14
15
  }
15
16
  }
@@ -45,8 +45,8 @@ export class ModuleAccessController {
45
45
  @Get('ui-config')
46
46
  async getModuleUIConfig(@Query('module_code') moduleCode: string, @Request() req) {
47
47
  const userId = req.user.userId;
48
-
49
- const roles = await this.menuRepository.getUserRoles(userId); // returns ['1', '4']
48
+ const appcode = req.user.appcode;
49
+ const roles = await this.menuRepository.getUserRoles(userId,appcode); // returns ['1', '4']
50
50
 
51
51
  if (!roles || roles.length === 0) {
52
52
  throw new BadRequestException('User has no roles');
@@ -34,4 +34,7 @@ export class MenuData {
34
34
 
35
35
  @Column({ type: 'int', nullable: true })
36
36
  ui_visible: number;
37
+
38
+ @Column({ type: 'varchar', nullable: true })
39
+ appcode: string;
37
40
  }
@@ -18,5 +18,5 @@ export class ModuleAccess {
18
18
  action_type: string;
19
19
 
20
20
  @Column({type: 'varchar', length: 100, nullable: true})
21
- app_code: string;
21
+ appcode: string;
22
22
  }
@@ -40,4 +40,7 @@ export class ModuleData {
40
40
 
41
41
  @Column({ type: 'json', nullable: true })
42
42
  ui_config: JSON;
43
+
44
+ @Column({ type: 'varchar', length: 100, nullable: true })
45
+ appcode: string;
43
46
  }
@@ -14,59 +14,64 @@ export class MenuRepository extends Repository<MenuData> {
14
14
  /**
15
15
  * Get all role IDs assigned to a user.
16
16
  */
17
- async getUserRoles(userId: number): Promise<number[]> {
17
+ async getUserRoles(userId: number, appcode: string): Promise<number[]> {
18
18
  const roles = await this.dataSource
19
19
  .getRepository(UserRoleMapping)
20
- .createQueryBuilder('userRoleMapping')
21
- .select('userRoleMapping.role_id')
22
- .where('userRoleMapping.user_id = :userId', { userId })
23
- .getMany();
24
-
25
- return roles.map((role) => role.role_id);
20
+ .createQueryBuilder('urm')
21
+ .innerJoin('cr_role', 'role', 'role.id = urm.role_id') // manual join
22
+ .select('urm.role_id')
23
+ .where('urm.user_id = :userId', { userId })
24
+ .andWhere('role.appcode = :appcode', { appcode })
25
+ .getRawMany();
26
+
27
+ return roles. map((r) => r.urm_role_id);
26
28
  }
29
+
27
30
 
28
31
  /**
29
32
  * Get module codes that the user has access to based on their role IDs.
30
- */
31
- async getAccessibleModules(roleIds: number[]): Promise<string[]> {
32
- // Get role codes from role IDs
33
- const roleCodes = await this.dataSource
34
- .getRepository(Role)
35
- .createQueryBuilder('role')
36
- .select('role.code')
37
- .where('role.id IN (:...roleIds)', { roleIds })
38
- .getMany();
33
+ */async getAccessibleModules(roleIds: number[], appCode: string): Promise<string[]> {
34
+ // Get role codes from role IDs
35
+ const roleCodes = await this.dataSource
36
+ .getRepository(Role)
37
+ .createQueryBuilder('role')
38
+ .select('role.code')
39
+ .where('role.id IN (:...roleIds)', { roleIds })
40
+ .getMany();
39
41
 
40
- const codes = roleCodes.map((role) => role.code);
42
+ const codes = roleCodes.map((role) => role.code);
41
43
 
42
- if (codes.length === 0) {
43
- return [];
44
- }
44
+ if (codes.length === 0) {
45
+ return [];
46
+ }
45
47
 
46
- // Get accessible modules using role codes
47
- const modules = await this.dataSource
48
- .getRepository(ModuleAccess)
49
- .createQueryBuilder('moduleAccess')
50
- .select('moduleAccess.module_code')
51
- .where('moduleAccess.role_code IN (:...codes)', { codes })
52
- .andWhere('moduleAccess.access_flag > 0')
53
- .getMany();
48
+ // Get accessible modules using role codes and appCode
49
+ const modules = await this.dataSource
50
+ .getRepository(ModuleAccess)
51
+ .createQueryBuilder('moduleAccess')
52
+ .select('moduleAccess.module_code')
53
+ .where('moduleAccess.role_code IN (:...codes)', { codes })
54
+ .andWhere('moduleAccess.access_flag > 0')
55
+ .andWhere('LOWER(moduleAccess.appcode) = LOWER(:appCode)', { appCode }) // case-insensitive
56
+ .getMany();
54
57
 
55
- return modules.map((module) => module.module_code);
56
- }
58
+ return modules.map((module) => module.module_code);
59
+ }
57
60
 
58
- async getMenuItems(moduleCodes: string[]): Promise<MenuData[]> {
59
- const menuItems = await this.createQueryBuilder('menu')
60
- .leftJoin('cr_module', 'module', 'menu.module_code = module.module_code')
61
- .where('menu.module_code IN (:...moduleCodes)', { moduleCodes })
62
- .select([
63
- 'menu.*',
64
- 'module.component_name AS component',
65
- 'module.title AS title',
66
- 'module.entity_type AS entity_type',
67
- ])
68
- .getRawMany();
61
+ async getMenuItems(moduleCodes: string[], appcode: string): Promise<MenuData[]> {
62
+ const menuItems = await this.createQueryBuilder('menu')
63
+ .leftJoin('cr_module', 'module', 'menu.module_code = module.module_code')
64
+ .where('menu.module_code IN (:...moduleCodes)', { moduleCodes })
65
+ .andWhere('LOWER(module.appcode) = LOWER(:appcode)', { appcode }) // appcode filter
66
+ .select([
67
+ 'menu.*',
68
+ 'module.component_name AS component',
69
+ 'module.title AS title',
70
+ 'module.entity_type AS entity_type',
71
+ ])
72
+ .getRawMany();
73
+
74
+ return menuItems;
75
+ }
69
76
 
70
- return menuItems;
71
- }
72
77
  }
@@ -122,7 +122,7 @@ export class ModuleAccessRepository {
122
122
  role_code: access.role_code,
123
123
  module_code: access.module_code,
124
124
  action_type: access.action_type,
125
- app_code: access.app_code,
125
+ appcode: access.app_code,
126
126
  },
127
127
  });
128
128
 
@@ -9,22 +9,22 @@ export class MenuService {
9
9
  /**
10
10
  * Fetch and construct menu hierarchy for a given user.
11
11
  */
12
- async getUserMenu(userId: number) {
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);
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
20
  const moduleCodes =
21
- await this.menuRepository.getAccessibleModules(roleCodes);
21
+ await this.menuRepository.getAccessibleModules(roleCodes,appcode);
22
22
  if (!moduleCodes.length) {
23
23
  return { menu: [] }; // Return empty menu if no accessible modules
24
24
  }
25
25
 
26
26
  // Step 3: Get the menu items based on accessible modules
27
- const menuItems = await this.menuRepository.getMenuItems(moduleCodes);
27
+ const menuItems = await this.menuRepository.getMenuItems(moduleCodes,appcode);
28
28
 
29
29
  // Step 4: Build hierarchical menu structure
30
30
  const menuTree = this.buildMenuHierarchy(menuItems);
@@ -10,9 +10,6 @@ export class Role extends BaseEntity {
10
10
  this.entity_type = ENTITYTYPE_ROLE;
11
11
  }
12
12
 
13
- @Column({ length: 50, type: 'varchar', nullable: true })
14
- app_code: string;
15
-
16
13
  @Column({ type: 'int', nullable: true })
17
14
  is_system: number;
18
15
 
@@ -23,4 +23,7 @@ export class UserRoleMapping {
23
23
 
24
24
  @Column({ type: 'int', nullable: true })
25
25
  is_default: number;
26
+
27
+ @Column({type: 'varchar'})
28
+ appcode: string;
26
29
  }
@@ -51,7 +51,7 @@ export class RoleService extends EntityServiceImpl {
51
51
  module_code: perm.module_code,
52
52
  action_type: perm.action_type,
53
53
  access_flag: perm.access_flag,
54
- app_code: perm.app_code,
54
+ appcode: perm.appcode,
55
55
  }),
56
56
  );
57
57
 
@@ -128,7 +128,7 @@ export class RoleService extends EntityServiceImpl {
128
128
  module_code: perm.module_code,
129
129
  action_type: perm.action_type,
130
130
  access_flag: perm.access_flag,
131
- app_code: perm.app_code,
131
+ appcode: perm.appcode,
132
132
  }),
133
133
  );
134
134