rez_core 2.0.95 → 2.0.97

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.0.95",
3
+ "version": "2.0.97",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,12 +1,11 @@
1
- import { Injectable, BadRequestException, Inject } from '@nestjs/common';
1
+ import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
2
  import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
3
3
  import { EntityMasterService } from 'src/module/meta/service/entity-master.service';
4
+ import { EntityTableColumnService } from 'src/module/meta/service/entity-table-column.service';
5
+ import { EntityTableService } from 'src/module/meta/service/entity-table.service';
4
6
  import { DataSource } from 'typeorm';
5
- import { SavedFilterService } from './saved-filter.service';
6
7
  import { FilterRequestDto } from '../dto/filter-request.dto';
7
- import { EntityTableService } from 'src/module/meta/service/entity-table.service';
8
- import { EntityTableColumnService } from 'src/module/meta/service/entity-table-column.service';
9
- import { get } from 'http';
8
+ import { SavedFilterService } from './saved-filter.service';
10
9
 
11
10
  @Injectable()
12
11
  export class FilterService {
@@ -19,7 +18,7 @@ export class FilterService {
19
18
  @Inject('SavedFilterService')
20
19
  private readonly savedFilterService: SavedFilterService,
21
20
  ) {}
22
- private readonly skipLevelFilterEntities = ['USR', 'UPR'];
21
+ private readonly skipLevelFilterEntities = [];
23
22
 
24
23
  private async gettab_value_counts(
25
24
  tableName: string,
@@ -129,11 +128,7 @@ export class FilterService {
129
128
 
130
129
  const baseWhere = this.buildWhereClauses(baseFilters, attributeMetaMap);
131
130
 
132
- if (
133
- level_type &&
134
- level_id &&
135
- !this.skipLevelFilterEntities.includes(entity_type)
136
- ) {
131
+ if (level_type && level_id) {
137
132
  baseWhere.push({
138
133
  query: 'e.level_type = :level_type AND e.level_id = :level_id',
139
134
  params: {
@@ -411,11 +411,11 @@ export class MasterService {
411
411
  row.entity_type = entityType;
412
412
  row.organization_id = loggedInUser.organization_id;
413
413
 
414
- const rowErrors =
415
- await this.entityValidationService.validateExcelEntityData(
416
- row,
417
- entityMaster,
418
- );
414
+ const rowErrors = await this.entityValidationService.validateEntityData(
415
+ row,
416
+ entityMaster,
417
+ loggedInUser,
418
+ );
419
419
 
420
420
  const existingError = errors.find((e) => e.row === i + 1);
421
421
 
@@ -466,13 +466,13 @@ export class MasterService {
466
466
  .andWhere(`${entityMaster.db_table_name}.level_id = :levelId`, {
467
467
  levelId: loggedInUser.level_id,
468
468
  });
469
-
469
+
470
470
  const existing = await qb.limit(1).getRawOne();
471
471
 
472
472
  row.entity_type = entityType;
473
473
  row.organization_id = loggedInUser.organization_id;
474
- row.status="ACTIVE"
475
-
474
+ row.status = 'ACTIVE';
475
+
476
476
  let errors = [];
477
477
  if (existing) {
478
478
  if (duplicateHandling === 'skip_duplicates') continue;
@@ -47,6 +47,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
47
47
  await this.entityValidationService.validateEntityData(
48
48
  entityData,
49
49
  entityMaster,
50
+ loggedInUser,
50
51
  );
51
52
  if (validationErrors.length > 0) {
52
53
  throw new BadRequestException({
@@ -49,6 +49,7 @@ export class EntityValidationService {
49
49
  attributeData: AttributeMaster[],
50
50
  entityType: string,
51
51
  db_table_name: string,
52
+ loggedInUser: any,
52
53
  ): Promise<ValidationError[]> {
53
54
  const errors: ValidationError[] = [];
54
55
 
@@ -64,12 +65,16 @@ export class EntityValidationService {
64
65
 
65
66
  // Add AND condition for organization_id if present
66
67
  const orgId = entityData.organization_id;
68
+ const level_type = loggedInUser.level_type;
69
+ const level_id = loggedInUser.level_id;
67
70
 
68
71
  if (orgId !== undefined && orgId !== null) {
69
72
  qb = qb.andWhere(
70
- `${db_table_name}.organization_id = :organization_id`,
73
+ `${db_table_name}.organization_id = :organization_id AND ${db_table_name}.level_type = :level_type AND ${db_table_name}.level_id = :level_id`,
71
74
  {
72
75
  organization_id: orgId,
76
+ level_type: level_type,
77
+ level_id: level_id,
73
78
  },
74
79
  );
75
80
  }
@@ -119,6 +124,7 @@ export class EntityValidationService {
119
124
  async validateEntityData(
120
125
  entityData: Record<string, any>,
121
126
  entityMaster,
127
+ loggedInUser: any,
122
128
  ): Promise<ValidationError[]> {
123
129
  const attributes =
124
130
  await this.attributeMasterService.findAttributesByMappedEntityType(
@@ -131,6 +137,7 @@ export class EntityValidationService {
131
137
  attributes,
132
138
  entityData.entity_type,
133
139
  entityMaster.db_table_name,
140
+ loggedInUser,
134
141
  );
135
142
  const regexErros = await this.validateRegexFields(entityData, attributes);
136
143
  return [...requiredErrors, ...uniqueErrors, ...regexErros];
@@ -5,6 +5,7 @@ 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 { level } from 'winston';
8
9
 
9
10
  @Injectable()
10
11
  export class ModuleAccessRepository {
@@ -34,22 +35,20 @@ export class ModuleAccessRepository {
34
35
  const where: any = { appcode };
35
36
  if (level_type) where.level_type = level_type;
36
37
  if (level_id !== undefined) where.level_id = String(level_id);
37
-
38
+
38
39
  const roles = await this.roleRepo.find({ where });
39
-
40
+
40
41
  return roles.map((role) => ({
41
42
  label: role.name,
42
43
  value: role.id,
43
44
  }));
44
45
  }
45
-
46
-
47
46
 
48
47
  async getModules({ appcode }: { appcode: string }) {
49
48
  const modules = await this.moduleRepo.find({
50
49
  where: { module_level: 'MAINMOD', appcode },
51
50
  });
52
-
51
+
53
52
  return modules
54
53
  .map((mod) => ({
55
54
  label: mod.name,
@@ -58,8 +57,12 @@ export class ModuleAccessRepository {
58
57
  }))
59
58
  .sort((a, b) => a.group.localeCompare(b.group));
60
59
  }
61
-
62
- async getAccessListing(roleIds: number[], appcode: string, levelType: string) {
60
+
61
+ async getAccessListing(
62
+ roleIds: number[],
63
+ appcode: string,
64
+ levelType: string,
65
+ ) {
63
66
  const roles = await this.roleRepo.find({
64
67
  where: { id: In(roleIds), appcode },
65
68
  });
@@ -70,7 +73,6 @@ export class ModuleAccessRepository {
70
73
  where: {
71
74
  role_code: In(roleCodes),
72
75
  appcode,
73
- level_type: levelType,
74
76
  },
75
77
  });
76
78
 
@@ -83,6 +85,7 @@ export class ModuleAccessRepository {
83
85
  action: access.action_type,
84
86
  access: access.access_flag,
85
87
  code: access.module_code,
88
+ level_type: access.level_type,
86
89
  })),
87
90
  }));
88
91
  }
@@ -90,54 +93,62 @@ export class ModuleAccessRepository {
90
93
  async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
91
94
  const mainModules =
92
95
  mainModIds.length === 1 && mainModIds[0] === '-1'
93
- ? await this.moduleRepo.find({ where: { module_level: 'MAINMOD', appcode } })
96
+ ? await this.moduleRepo.find({
97
+ where: { module_level: 'MAINMOD', appcode },
98
+ })
94
99
  : await this.moduleRepo.find({
95
100
  where: { id: In(mainModIds), module_level: 'MAINMOD', appcode },
96
101
  });
97
-
102
+
98
103
  if (!mainModules.length) return {};
99
-
104
+
100
105
  const wbsCodes = mainModules.map((mod) => mod.wbs_code);
101
-
106
+
102
107
  const allModules = await this.moduleRepo
103
108
  .createQueryBuilder('module')
104
109
  .where(
105
- wbsCodes.map((code) => `module.wbs_code LIKE :code${code}`).join(' OR '),
110
+ wbsCodes
111
+ .map((code) => `module.wbs_code LIKE :code${code}`)
112
+ .join(' OR '),
106
113
  Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
107
114
  )
108
115
  .andWhere('module.appcode = :appcode', { appcode })
109
116
  .getMany();
110
-
117
+
111
118
  const moduleCodes = allModules.map((m) => m.module_code);
112
-
119
+
113
120
  const allActions = await this.moduleActionRepo.find({
114
121
  where: { module_code: In(moduleCodes) },
115
122
  });
116
-
123
+
117
124
  // Map actions by module_code with full permission object
118
- const actionMap = allActions.reduce((acc, action) => {
119
- if (!acc[action.module_code]) acc[action.module_code] = [];
120
- acc[action.module_code].push({
121
- action: action.action_type,
122
- name: action.action_name,
123
- // You can also include action_type here if needed
124
- });
125
- return acc;
126
- }, {} as Record<string, { action: string; name: string }[]>);
127
-
125
+ const actionMap = allActions.reduce(
126
+ (acc, action) => {
127
+ if (!acc[action.module_code]) acc[action.module_code] = [];
128
+ acc[action.module_code].push({
129
+ action: action.action_type,
130
+ name: action.action_name,
131
+ // You can also include action_type here if needed
132
+ });
133
+ return acc;
134
+ },
135
+ {} as Record<string, { action: string; name: string }[]>,
136
+ );
137
+
128
138
  const levelsToReturn = levelType === 'ORG' ? ['ORG', 'SCH'] : ['SCH'];
129
-
139
+
130
140
  const groupedByLevel: Record<string, any[]> = {};
131
-
141
+
132
142
  for (const lvl of levelsToReturn) {
133
143
  const filteredModules = allModules.filter((m) => m.level_type === lvl);
134
-
144
+
135
145
  const buildHierarchy = (parentWbs: string): any[] =>
136
146
  filteredModules
137
147
  .filter(
138
148
  (mod) =>
139
149
  mod.wbs_code.startsWith(`${parentWbs}.`) &&
140
- mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
150
+ mod.wbs_code.split('.').length ===
151
+ parentWbs.split('.').length + 1,
141
152
  )
142
153
  .map((mod) => ({
143
154
  name: mod.name,
@@ -145,7 +156,7 @@ export class ModuleAccessRepository {
145
156
  permission: actionMap[mod.module_code] || [],
146
157
  submod: buildHierarchy(mod.wbs_code),
147
158
  }));
148
-
159
+
149
160
  const levelModules = mainModules
150
161
  .filter((mod) => mod.level_type === lvl)
151
162
  .map((mod) => ({
@@ -154,14 +165,13 @@ export class ModuleAccessRepository {
154
165
  permission: actionMap[mod.module_code] || [],
155
166
  submod: buildHierarchy(mod.wbs_code),
156
167
  }));
157
-
168
+
158
169
  if (levelModules.length) {
159
170
  groupedByLevel[lvl] = levelModules;
160
171
  }
161
172
  }
162
173
  return groupedByLevel;
163
174
  }
164
-
165
175
 
166
176
  async updateModuleAccess(
167
177
  accessList: {