rez_core 5.0.167 → 5.0.169

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 (38) hide show
  1. package/dist/module/entity_json/service/entity_json.service.js +5 -5
  2. package/dist/module/entity_json/service/entity_json.service.js.map +1 -1
  3. package/dist/module/filter/repository/saved-filter.repository.d.ts +4 -6
  4. package/dist/module/filter/repository/saved-filter.repository.js +43 -9
  5. package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
  6. package/dist/module/filter/service/filter.service.js +4 -5
  7. package/dist/module/filter/service/filter.service.js.map +1 -1
  8. package/dist/module/meta/dto/entity-table.dto.d.ts +1 -4
  9. package/dist/module/meta/repository/attribute-master.repository.d.ts +5 -2
  10. package/dist/module/meta/repository/attribute-master.repository.js +27 -22
  11. package/dist/module/meta/repository/attribute-master.repository.js.map +1 -1
  12. package/dist/module/meta/repository/entity-master.repository.d.ts +1 -1
  13. package/dist/module/meta/repository/entity-master.repository.js +5 -10
  14. package/dist/module/meta/repository/entity-master.repository.js.map +1 -1
  15. package/dist/module/meta/service/attribute-master.service.js +2 -1
  16. package/dist/module/meta/service/attribute-master.service.js.map +1 -1
  17. package/dist/module/meta/service/entity-dynamic.service.js +19 -15
  18. package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
  19. package/dist/module/meta/service/entity-master.service.js +2 -2
  20. package/dist/module/meta/service/entity-master.service.js.map +1 -1
  21. package/dist/module/meta/service/entity-relation.service.d.ts +1 -1
  22. package/dist/module/meta/service/entity-relation.service.js +4 -4
  23. package/dist/module/meta/service/entity-relation.service.js.map +1 -1
  24. package/dist/module/meta/service/resolver.service.js +4 -4
  25. package/dist/module/meta/service/resolver.service.js.map +1 -1
  26. package/dist/tsconfig.build.tsbuildinfo +1 -1
  27. package/package.json +1 -1
  28. package/src/module/entity_json/service/entity_json.service.ts +5 -5
  29. package/src/module/filter/repository/saved-filter.repository.ts +65 -9
  30. package/src/module/filter/service/filter.service.ts +5 -5
  31. package/src/module/meta/dto/entity-table.dto.ts +2 -2
  32. package/src/module/meta/repository/attribute-master.repository.ts +41 -33
  33. package/src/module/meta/repository/entity-master.repository.ts +6 -10
  34. package/src/module/meta/service/attribute-master.service.ts +2 -1
  35. package/src/module/meta/service/entity-dynamic.service.ts +19 -15
  36. package/src/module/meta/service/entity-master.service.ts +2 -2
  37. package/src/module/meta/service/entity-relation.service.ts +4 -4
  38. package/src/module/meta/service/resolver.service.ts +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "5.0.167",
3
+ "version": "5.0.169",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -25,6 +25,7 @@ export class EntityJSONService extends EntityServiceImpl {
25
25
  flag?: 'flat_json' | 'dropdown' | 'all',
26
26
  ) {
27
27
  const orgId = loggedInUser.organization_id;
28
+ const entId = loggedInUser.entId;
28
29
 
29
30
  await this.loggerService.log('info', 'EntityJSONService', 'getAttributeForFlatJSON', `Loading attributes for entity: ${entityType}, org: ${orgId}`);
30
31
 
@@ -33,7 +34,7 @@ export class EntityJSONService extends EntityServiceImpl {
33
34
  .createQueryBuilder('attr')
34
35
  .select(['attr.id', 'attr.name', 'attr.flat_json_key', 'attr.attribute_key'])
35
36
  .where('attr.mapped_entity_type = :entityType', { entityType })
36
- .andWhere('attr.organization_id = :orgId', { orgId })
37
+ .andWhere('attr.enterprise_id = :entId', { entId })
37
38
  .getMany();
38
39
 
39
40
  await this.loggerService.log('debug', 'EntityJSONService', 'getAttributeForFlatJSON', `Loaded ${mainAttributes.length} main attributes`);
@@ -43,7 +44,7 @@ export class EntityJSONService extends EntityServiceImpl {
43
44
  .createQueryBuilder('rel')
44
45
  .select(['rel.target_entity_type'])
45
46
  .where('rel.source_entity_type = :entityType', { entityType })
46
- .andWhere('rel.organization_id = :orgId', { orgId })
47
+ .andWhere('rel.enterprise_id = :entId', { entId })
47
48
  .andWhere('rel.relation_type = :relationType', { relationType: 'ONE_TO_ONE' })
48
49
  .getRawMany();
49
50
 
@@ -57,7 +58,7 @@ export class EntityJSONService extends EntityServiceImpl {
57
58
  .createQueryBuilder('attr')
58
59
  .select(['attr.id', 'attr.name', 'attr.flat_json_key', 'attr.mapped_entity_type', 'attr.attribute_key'])
59
60
  .where('attr.mapped_entity_type IN (:...types)', { types: relatedTypesList })
60
- .andWhere('attr.organization_id = :orgId', { orgId })
61
+ .andWhere('attr.enterprise_id = :entId', { entId })
61
62
  .getMany()
62
63
  : [];
63
64
 
@@ -79,7 +80,7 @@ export class EntityJSONService extends EntityServiceImpl {
79
80
  'attr.name AS name',
80
81
  'attr.id AS id',
81
82
  ])
82
- .where('attr.organization_id = :orgId', { orgId })
83
+ .where('attr.enterprise_id = :entId', { entId })
83
84
  .getRawMany();
84
85
 
85
86
  await this.loggerService.log('debug', 'EntityJSONService', 'getAttributeForFlatJSON', `Loaded ${linkedAttributes.length} linked attributes`);
@@ -219,7 +220,6 @@ export class EntityJSONService extends EntityServiceImpl {
219
220
 
220
221
  const dto: any = {
221
222
  entity_type: childEntityType,
222
- loggedInUser,
223
223
  savedFilterCode,
224
224
  page: 1,
225
225
  size: 1,
@@ -5,7 +5,8 @@ import { SavedFilterMaster } from '../entity/saved-filter-master.entity';
5
5
  import { SavedFilterDetail } from '../entity/saved-filter-detail.entity';
6
6
  import { UserData } from 'src/module/user/entity/user.entity';
7
7
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
8
- import { log } from 'console';
8
+ import { ConfigService } from '@nestjs/config';
9
+ import axios from 'axios';
9
10
 
10
11
  @Injectable()
11
12
  export class SavedFilterRepositoryService {
@@ -15,6 +16,7 @@ export class SavedFilterRepositoryService {
15
16
  @InjectRepository(SavedFilterDetail)
16
17
  private readonly savedFilterDetailRepo: Repository<SavedFilterDetail>,
17
18
  private readonly reflectionHelper: ReflectionHelper,
19
+ private readonly configService: ConfigService,
18
20
  ) {}
19
21
 
20
22
  async isFilterNameExists({
@@ -88,12 +90,13 @@ export class SavedFilterRepositoryService {
88
90
  }
89
91
 
90
92
  async getSavedFiltersByUserIdAndEntityType(
91
- userId: number,
93
+ loggedInUser: UserData,
94
+ // userId: number,
92
95
  entityType: string,
93
96
  ) {
94
97
  const filters = await this.savedFilterMasterRepo.find({
95
98
  where: {
96
- user_id: userId,
99
+ user_id: loggedInUser.id,
97
100
  mapped_entity_type: entityType,
98
101
  status: 'ACTIVE',
99
102
  },
@@ -102,12 +105,39 @@ export class SavedFilterRepositoryService {
102
105
  },
103
106
  });
104
107
 
105
- return filters.map((filter) => ({
106
- label: filter.name,
107
- value: filter.id,
108
- code: filter.code,
109
- }));
110
- // return filters;
108
+ if (!filters?.length) {
109
+ for (const filter of filters) {
110
+ try {
111
+ const baseUrl = this.configService.get<string>('REDIRECT_BE_URL');
112
+ const queryParams = new URLSearchParams({
113
+ loggedInUser: JSON.stringify(loggedInUser),
114
+ }).toString();
115
+
116
+ const createdBy = await axios.get(
117
+ `${baseUrl}/users/profile-image-url/${filter.created_by}?entity_type=USR&${queryParams}`,
118
+ { headers: { 'Content-Type': 'application/json' } },
119
+ );
120
+
121
+ const modifiedBy = await axios.get(
122
+ `${baseUrl}/users/profile-image-url/${filter.modified_by}?entity_type=USR&${queryParams}`,
123
+ { headers: { 'Content-Type': 'application/json' } },
124
+ );
125
+
126
+ filter.created_by = createdBy.data.name;
127
+ filter.modified_by = modifiedBy.data.name;
128
+ } catch (err) {
129
+ console.error('⚠ Error fetching profile:', err.message);
130
+ }
131
+ }
132
+ }
133
+
134
+ // return filters.map((filter) => ({
135
+ // label: filter.name,
136
+ // value: filter.id,
137
+ // code: filter.code,
138
+ // }));
139
+
140
+ return filters;
111
141
  }
112
142
 
113
143
  async getSharedFiltersByLevelTypeAndLevelId(
@@ -128,6 +158,32 @@ export class SavedFilterRepositoryService {
128
158
  },
129
159
  });
130
160
 
161
+ if (!filters?.length) {
162
+ for (const filter of filters) {
163
+ try {
164
+ const baseUrl = this.configService.get<string>('REDIRECT_BE_URL');
165
+ const queryParams = new URLSearchParams({
166
+ loggedInUser: JSON.stringify(loggedInUser),
167
+ }).toString();
168
+
169
+ const createdBy = await axios.get(
170
+ `${baseUrl}/users/profile-image-url/${filter.created_by}?entity_type=USR&${queryParams}`,
171
+ { headers: { 'Content-Type': 'application/json' } },
172
+ );
173
+
174
+ const modifiedBy = await axios.get(
175
+ `${baseUrl}/users/profile-image-url/${filter.modified_by}?entity_type=USR&${queryParams}`,
176
+ { headers: { 'Content-Type': 'application/json' } },
177
+ );
178
+
179
+ filter.created_by = createdBy.data.name;
180
+ filter.modified_by = modifiedBy.data.name;
181
+ } catch (err) {
182
+ console.error('⚠ Error fetching profile:', err.message);
183
+ }
184
+ }
185
+ }
186
+
131
187
  return filters;
132
188
 
133
189
  // return filters.map((filter) => ({
@@ -78,11 +78,12 @@ export class FilterService {
78
78
 
79
79
  const rawSQL = `
80
80
  SELECT ${column} AS tab_value, COUNT(*) AS tab_value_count
81
- FROM ${tableName} ${whereSQL}
81
+ FROM ${this.schema}.${tableName} ${whereSQL}
82
82
  GROUP BY ${column}
83
83
  `;
84
84
 
85
- const rows = await this.queryWithSchema(rawSQL, values);
85
+
86
+ const rows = await this.entityManager.query(rawSQL, values);
86
87
 
87
88
  const total = rows.reduce(
88
89
  (sum, r) => sum + parseInt(r.tab_value_count, 10),
@@ -166,7 +167,7 @@ export class FilterService {
166
167
  entity_type,
167
168
  subEntityType,
168
169
  subEntityIds,
169
- dto.loggedInUser.organization_id,
170
+ dto.loggedInUser.enterprise_id,
170
171
  );
171
172
 
172
173
  intersectionIds =
@@ -1310,8 +1311,7 @@ export class FilterService {
1310
1311
 
1311
1312
  async queryWithSchema(sql: string, params: any[] = []) {
1312
1313
  await this.entityManager.query('BEGIN');
1313
- const schema = this.configService.get<string>('DB_SCHEMA');
1314
- await this.entityManager.query(`SET LOCAL search_path TO ${schema}`);
1314
+ await this.entityManager.query(`SET LOCAL search_path TO ${this.schema}`);
1315
1315
  const result = await this.entityManager.query(sql, params);
1316
1316
  await this.entityManager.query('COMMIT');
1317
1317
  return result;
@@ -5,8 +5,8 @@ export class EntityTableDto extends EntityTable {
5
5
  column_list: EntityTableColumn[];
6
6
  operation_list: {};
7
7
  default_filter: {} | null;
8
- saved_filter: { label: string; value: number }[] | null;
8
+ // saved_filter: { label: string; value: number }[] | null;
9
9
  // shared_filter: { label: string; value: number }[] | null;
10
10
  shared_filter: any[] | null;
11
- // saved_filter: any[] | null;
11
+ saved_filter: any[] | null;
12
12
  }
@@ -4,6 +4,7 @@ import { AttributeMaster } from '../entity/attribute-master.entity';
4
4
  import { EntityManager, Repository } from 'typeorm';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
6
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
7
+ import { ConfigService } from '@nestjs/config';
7
8
 
8
9
  @Injectable()
9
10
  export class AttributeMasterRepository {
@@ -12,7 +13,11 @@ export class AttributeMasterRepository {
12
13
  private readonly attributeMasterRepository: Repository<AttributeMaster>,
13
14
  private readonly entityManger: EntityManager,
14
15
  private readonly reflectionHelper: ReflectionHelper,
15
- ) {}
16
+ private readonly configService: ConfigService,
17
+ ) {
18
+ }
19
+
20
+ schema = this.configService.get('DB_SCHEMA');
16
21
 
17
22
  // ---------- Existing Methods ----------
18
23
  async findByMappedEntityIdAndMappedEntityTypeAndAttributeKeyAndOrganizationId(
@@ -38,7 +43,7 @@ export class AttributeMasterRepository {
38
43
  return await this.attributeMasterRepository.find({
39
44
  where: {
40
45
  mapped_entity_type: entityType,
41
- organization_id: loggedInUser.organization_id,
46
+ enterprise_id: loggedInUser.enterprise_id,
42
47
  },
43
48
  });
44
49
  }
@@ -61,25 +66,27 @@ export class AttributeMasterRepository {
61
66
  return await this.attributeMasterRepository.findOne({ where: { id } });
62
67
  }
63
68
 
64
- async getAllAttributeByEntity(entity_type:string,loggedInUser):Promise<{ label: string; value: any }[]> {
65
- let data = await this.attributeMasterRepository.find({
66
- where: {
67
- organization_id: loggedInUser.organization_id,
68
- mapped_entity_type: entity_type
69
- }
70
- });
71
- if(data) {
72
- const dropdownData = data.map((attribute) => {
73
- return {"label": attribute.name,
74
- "value":attribute.attribute_key,
75
- "data_type":attribute.data_type,
76
- "data_source_list":attribute.datasource_list
69
+ async getAllAttributeByEntity(entity_type: string, loggedInUser): Promise<{ label: string; value: any }[]> {
70
+ let data = await this.attributeMasterRepository.find({
71
+ where: {
72
+ enterprise_id: loggedInUser.enterprise_id,
73
+ mapped_entity_type: entity_type,
74
+ },
75
+ });
76
+ if (data) {
77
+ const dropdownData = data.map((attribute) => {
78
+ return {
79
+ 'label': attribute.name,
80
+ 'value': attribute.attribute_key,
81
+ 'data_type': attribute.data_type,
82
+ 'data_source_list': attribute.datasource_list,
83
+ };
84
+ });
85
+
86
+ return dropdownData;
87
+ }
88
+ return [];
77
89
  }
78
- })
79
-
80
- return dropdownData;
81
- }
82
- return []; }
83
90
 
84
91
  async getAttributesDropdownList(
85
92
  entityType: string,
@@ -88,7 +95,7 @@ return dropdownData;
88
95
  const data = await this.attributeMasterRepository.find({
89
96
  where: {
90
97
  mapped_entity_type: entityType,
91
- organization_id: loggedInUser.organization_id,
98
+ enterprise_id: loggedInUser.enterprise_id,
92
99
  },
93
100
  });
94
101
 
@@ -107,7 +114,7 @@ return dropdownData;
107
114
  const result = await entityMasterRepo.findOne({
108
115
  where: {
109
116
  mapped_entity_type: entityType,
110
- organization_id: loggedInUser.organization_id,
117
+ enterprise_id: loggedInUser.enterprise_id,
111
118
  },
112
119
  });
113
120
  if (result) {
@@ -122,11 +129,11 @@ return dropdownData;
122
129
  ): Promise<boolean> {
123
130
  const result = await this.entityManger.query(
124
131
  `
125
- SELECT column_name
126
- FROM information_schema.columns
127
- WHERE table_name = $1
128
- AND column_name = $2
129
- `,
132
+ SELECT column_name
133
+ FROM information_schema.columns
134
+ WHERE table_name = $1
135
+ AND column_name = $2
136
+ `,
130
137
  [tableName, columnName],
131
138
  );
132
139
 
@@ -138,19 +145,20 @@ return dropdownData;
138
145
  columnName: string,
139
146
  columnType: string,
140
147
  ): Promise<void> {
148
+
141
149
  const alterQuery = `
142
- ALTER TABLE "${tableName}"
143
- ADD COLUMN IF NOT EXISTS "${columnName}" ${columnType}
150
+ ALTER TABLE ${this.schema}.${tableName}
151
+ ADD COLUMN IF NOT EXISTS ${columnName} ${columnType}
144
152
  `;
145
153
 
146
154
  await this.entityManger.query(alterQuery);
147
155
  }
148
156
 
149
- async findByMappedEntityTypeAndAttributeKeyAndOrganizationId(mapped_entity_type: string, attribute_key: string, organization_id: number) {
157
+ async findByMappedEntityTypeAndAttributeKeyAndOrganizationId(mapped_entity_type: string, attribute_key: string, enterprise_id: number) {
150
158
  return await this.attributeMasterRepository.findOne({
151
159
  where: {
152
- mapped_entity_type, attribute_key, organization_id
153
- }
154
- })
160
+ mapped_entity_type, attribute_key, enterprise_id,
161
+ },
162
+ });
155
163
  }
156
164
  }
@@ -49,12 +49,8 @@ export class EntityMasterRepository {
49
49
  .getRawMany();
50
50
 
51
51
  // console.log(relations,"-------------")
52
- let parentEntityLabelName = await this.entityMasterRepository.findOne({
53
- where: {
54
- organization_id: loggedInUser.organization_id,
55
- mapped_entity_type: entity_type,
56
- },
57
- });
52
+ let parentEntityLabelName = await this.getEntityByMappedEntityType(entity_type, loggedInUser.enterprise_id);
53
+
58
54
  let dropdownData: any[] = [...relations];
59
55
  if (parentEntityLabelName) {
60
56
  dropdownData.push({
@@ -68,12 +64,12 @@ export class EntityMasterRepository {
68
64
 
69
65
  async getEntityByMappedEntityType(
70
66
  mappedEntityType: string,
71
- organizationId: any,
67
+ enterprise_id: any,
72
68
  ): Promise<EntityMaster | null> {
73
69
  return await this.entityMasterRepository.findOne({
74
70
  where: {
75
71
  mapped_entity_type: mappedEntityType,
76
- organization_id: organizationId,
72
+ enterprise_id: enterprise_id,
77
73
  },
78
74
  });
79
75
  }
@@ -92,13 +88,13 @@ export class EntityMasterRepository {
92
88
  }
93
89
 
94
90
  async getAttributesOfTypeDate(entity_type, loggedInUser) {
95
- const organization_id = loggedInUser.organization_id;
91
+ const enterprise_id = loggedInUser.enterprise_id;
96
92
 
97
93
  const attributes = await this.attributeMasterRepository.find({
98
94
  where: {
99
95
  mapped_entity_type: entity_type,
100
96
  data_type: 'DATE',
101
- organization_id
97
+ enterprise_id
102
98
  }
103
99
  })
104
100
 
@@ -25,6 +25,7 @@ export class AttributeMasterService {
25
25
  loggedInUser: UserData,
26
26
  ): Promise<AttributeMaster> {
27
27
  attributeData.organization_id = loggedInUser.organization_id;
28
+ attributeData.enterprise_id = loggedInUser.enterprise_id;
28
29
  attributeData.level_type = loggedInUser.level_type;
29
30
  attributeData.level_id = loggedInUser.level_id;
30
31
 
@@ -124,7 +125,7 @@ export class AttributeMasterService {
124
125
  return await this.attributeMasterRepository.findByMappedEntityTypeAndAttributeKeyAndOrganizationId(
125
126
  mapped_entity_type,
126
127
  attribute_key,
127
- loggedInUser.organization_id
128
+ loggedInUser.enterprise_id
128
129
  );
129
130
  }
130
131
  }
@@ -29,8 +29,9 @@ export class EntityDynamicService {
29
29
  mainID?: number,
30
30
  ): Promise<any> {
31
31
  const organizationId = loggedInUser.organization_id;
32
+ const enterprise_id = loggedInUser.enterprise_id;
32
33
 
33
- const tableName = await this.getTableName(entityType, organizationId);
34
+ const tableName = await this.getTableName(entityType, enterprise_id);
34
35
  const validAttributes = await this.getAttributeCodes(
35
36
  entityType,
36
37
  organizationId,
@@ -75,7 +76,7 @@ export class EntityDynamicService {
75
76
  // -------------------------------------------------------
76
77
  // AUTO-CODE GENERATION (POSTGRES SAFE)
77
78
  // -------------------------------------------------------
78
- const entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, loggedInUser.organization_id)
79
+ const entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, loggedInUser.enterprise_id)
79
80
 
80
81
  if (!entityData.code && entityData.entity_type && entityMaster) {
81
82
  // Extract integer suffix
@@ -444,8 +445,9 @@ export class EntityDynamicService {
444
445
  mainID?: number,
445
446
  ): Promise<any> {
446
447
  const organizationId = loggedInUser.organization_id;
448
+ const enterprise_id = loggedInUser.enterprise_id;
447
449
 
448
- const tableName = await this.getTableName(entityType, organizationId);
450
+ const tableName = await this.getTableName(entityType, enterprise_id);
449
451
  const validAttributes = await this.getAttributeCodes(
450
452
  entityType,
451
453
  organizationId,
@@ -529,10 +531,11 @@ export class EntityDynamicService {
529
531
  loggedInUser: any,
530
532
  ): Promise<any> {
531
533
  const organizationId = loggedInUser.organization_id;
534
+ const enterprise_id = loggedInUser.enterprise_id;
532
535
 
533
536
  const dataSource = await this.getEntitySourceTableName(
534
537
  entityType,
535
- organizationId,
538
+ enterprise_id,
536
539
  );
537
540
  const validAttributes = await this.getAttributeCodes(
538
541
  entityType,
@@ -583,9 +586,10 @@ export class EntityDynamicService {
583
586
  id: number | string,
584
587
  loggedInUser: any,
585
588
  ): Promise<any> {
589
+ const enterprise_id = loggedInUser.enterprise_id;
586
590
  const organizationId = loggedInUser.organization_id;
587
591
 
588
- const entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, organizationId);
592
+ const entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, enterprise_id);
589
593
  if(!entityMaster) return null;
590
594
 
591
595
  const validAttributes = await this.getAttributeCodes(
@@ -638,11 +642,11 @@ export class EntityDynamicService {
638
642
 
639
643
  private async getEntitySourceTableName(
640
644
  entityType: string,
641
- organizationId: string,
645
+ enterprise_id: string,
642
646
  ): Promise<string> {
643
647
  const result = await this.entityMasterRepo.getEntityByMappedEntityType(
644
648
  entityType,
645
- organizationId,
649
+ enterprise_id,
646
650
  );
647
651
 
648
652
  if (!result) {
@@ -656,11 +660,11 @@ export class EntityDynamicService {
656
660
  // -----------------------------
657
661
  private async getTableName(
658
662
  entityType: string,
659
- organizationId: string,
663
+ enterprise_id: string,
660
664
  ): Promise<string> {
661
665
  let entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(
662
666
  entityType,
663
- organizationId,
667
+ enterprise_id,
664
668
  );
665
669
 
666
670
  if (!entityMaster) {
@@ -709,12 +713,12 @@ export class EntityDynamicService {
709
713
  id: number | string,
710
714
  loggedInUser: any,
711
715
  ): Promise<any> {
712
- const organizationId = loggedInUser.organization_id;
716
+ const enterprise_id = loggedInUser.enterprise_id;
713
717
 
714
- const tableName = await this.getTableName(entityType, organizationId);
718
+ const tableName = await this.getTableName(entityType, enterprise_id);
715
719
 
716
720
  const deleteQuery = `DELETE
717
- FROM \`${tableName}\`
721
+ FROM ${this.schema}.${tableName}
718
722
  WHERE id = $1`;
719
723
  const result = await this.entityManager.query(deleteQuery, [id]);
720
724
  return result;
@@ -743,18 +747,18 @@ export class EntityDynamicService {
743
747
  }
744
748
 
745
749
  async getCode(entityType: string, loggedInUser: any): Promise<string> {
746
- const organizationId = loggedInUser.organization_id;
750
+ const enterprise_id = loggedInUser.enterprise_id;
747
751
 
748
752
  // 1. Get db_table_name from entity master
749
753
 
750
754
  const result = await this.entityMasterRepo.getEntityByMappedEntityType(
751
755
  entityType,
752
- organizationId,
756
+ enterprise_id,
753
757
  );
754
758
 
755
759
  if (!result) {
756
760
  throw new Error(
757
- `Entity type '${entityType}' not found in frm_entity_master for org '${organizationId}'`,
761
+ `Entity type '${entityType}' not found in frm_entity_master for enterprise '${enterprise_id}'`,
758
762
  );
759
763
  }
760
764
 
@@ -36,7 +36,7 @@ export class EntityMasterService {
36
36
  if (mappedEntityType) {
37
37
  let filterCondition = {
38
38
  mapped_entity_type: mappedEntityType,
39
- organization_id: loggedInUser.organization_id,
39
+ enterprise_id: loggedInUser.enterprise_id,
40
40
  };
41
41
  if (mapped_entity_id) {
42
42
  filterCondition['id'] = mapped_entity_id;
@@ -83,7 +83,7 @@ export class EntityMasterService {
83
83
  const entityMasterData =
84
84
  await this.entityMasterRepo.getEntityByMappedEntityType(
85
85
  entityType,
86
- loggedInUser.organization_id,
86
+ loggedInUser.enterprise_id,
87
87
  );
88
88
 
89
89
  if (!entityMasterData) {
@@ -25,11 +25,11 @@ export class EntityRelationService extends EntityServiceImpl {
25
25
  'er.id AS id',
26
26
  ])
27
27
  .where('er.source_entity_type = :entityType', { entityType })
28
- .andWhere('er.organization_id = :orgId', { orgId: loggedInUser.organization_id })
28
+ .andWhere('er.enterprise_id = :entId', { entId: loggedInUser.enterprise_id })
29
29
  .getRawMany();
30
30
 
31
31
  if (includeSelf) {
32
- const entity = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, loggedInUser.organization_id);
32
+ const entity = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, loggedInUser.enterprise_id);
33
33
 
34
34
  if (entity) {
35
35
  relations.unshift({
@@ -47,7 +47,7 @@ export class EntityRelationService extends EntityServiceImpl {
47
47
  sourceEntity: string,
48
48
  targetEntity: string,
49
49
  targetIds: number[],
50
- orgId: number,
50
+ enterpriseId: number,
51
51
  ): Promise<number[]> {
52
52
 
53
53
  if (!targetIds.length) return [];
@@ -59,7 +59,7 @@ export class EntityRelationService extends EntityServiceImpl {
59
59
  .where('erd.source_entity_type = :sourceEntity', { sourceEntity })
60
60
  .andWhere('erd.target_entity_type = :targetEntity', { targetEntity })
61
61
  .andWhere('erd.target_entity_id IN (:...targetIds)', { targetIds })
62
- .andWhere('erd.organization_id = :orgId', { orgId })
62
+ .andWhere('erd.enterprise_id = :enterpriseId', { enterpriseId })
63
63
  .getRawMany();
64
64
 
65
65
  return rows.map((r) => Number(r.source_entity_id));
@@ -140,12 +140,12 @@ export class ResolverService {
140
140
  }
141
141
 
142
142
  // fetch attribute meta only for the given attributeKey
143
- const attr = await this.attributeMasterRepo.findByMappedEntityTypeAndAttributeKeyAndOrganizationId(entityType, attrKey, loggedInUser.organization_id);
143
+ const attr = await this.attributeMasterRepo.findByMappedEntityTypeAndAttributeKeyAndOrganizationId(entityType, attrKey, loggedInUser.enterprise_id);
144
144
  if (!attr) return rawValue;
145
145
 
146
146
  // -------- ENTITY data_source_type --------
147
147
  if (attr.data_source_type === 'entity') {
148
- const entityDef = await this.entityMasterRepo.getEntityByMappedEntityType(attr.datasource_list, loggedInUser.organization_id);
148
+ const entityDef = await this.entityMasterRepo.getEntityByMappedEntityType(attr.datasource_list, loggedInUser.enterprise_id);
149
149
 
150
150
  if (!entityDef) return rawValue;
151
151
 
@@ -241,13 +241,13 @@ export class ResolverService {
241
241
  }
242
242
 
243
243
  // fetch attribute meta
244
- const attr = await this.attributeMasterRepo.findByMappedEntityTypeAndAttributeKeyAndOrganizationId(entityType, attrKey, loggedInUser.organization_id);
244
+ const attr = await this.attributeMasterRepo.findByMappedEntityTypeAndAttributeKeyAndOrganizationId(entityType, attrKey, loggedInUser.enterprise_id);
245
245
 
246
246
  if (!attr) return displayValue;
247
247
 
248
248
  // -------- ENTITY data_source_type --------
249
249
  if (attr.data_source_type === 'entity') {
250
- const entityDef =await this.entityMasterRepo.getEntityByMappedEntityType(attr.datasource_list, loggedInUser.organization_id);
250
+ const entityDef =await this.entityMasterRepo.getEntityByMappedEntityType(attr.datasource_list, loggedInUser.enterprise_id);
251
251
 
252
252
  if (!entityDef) return displayValue;
253
253