rez_core 3.1.0 → 3.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -8,6 +8,7 @@ import { FilterCondition, FilterRequestDto } from '../dto/filter-request.dto';
8
8
  import { SavedFilterService } from './saved-filter.service';
9
9
 
10
10
  import * as moment from 'moment';
11
+ import { EntityRelationService } from 'src/module/meta/service/entity-relation.service';
11
12
 
12
13
  @Injectable()
13
14
  export class FilterService {
@@ -17,6 +18,8 @@ export class FilterService {
17
18
  private readonly entityMasterService: EntityMasterService,
18
19
  @Inject('SavedFilterService')
19
20
  private readonly savedFilterService: SavedFilterService,
21
+ @Inject('EntityRelationService')
22
+ private readonly entityRelationService: EntityRelationService,
20
23
  ) {}
21
24
  private readonly skipAppCodeFilterEntities = ['ORGP'];
22
25
  private readonly skipOrgFilterEntities = ['ORGP'];
@@ -114,14 +117,29 @@ export class FilterService {
114
117
 
115
118
  const subResult = await this.applyFilter(subDto);
116
119
 
117
- // extract parent ids from sub entity result
118
- const parentIds = subResult.data.entity_list.map((row) => row.parent_id);
120
+ // new way (fetch source entity IDs via relation mapping)
121
+ const subEntityIds = subResult.data.entity_list.map((row) => row.id);
122
+
123
+ if (!subEntityIds.length) {
124
+ return {
125
+ success: true,
126
+ data: { entity_tabs: [], entity_list: [], pagination: {} },
127
+ };
128
+ }
129
+
130
+
131
+ const relatedIds = await this.entityRelationService.getRelatedEntityIds(
132
+ entity_type,
133
+ subEntityType,
134
+ subEntityIds,
135
+ dto.loggedInUser.organization_id,
136
+ );
119
137
 
120
138
  // keep intersection
121
139
  intersectionIds =
122
140
  intersectionIds === null
123
- ? parentIds
124
- : intersectionIds.filter((id) => parentIds.includes(id));
141
+ ? relatedIds
142
+ : intersectionIds.filter((id) => relatedIds.includes(id));
125
143
 
126
144
  // early exit if no intersection
127
145
  if (intersectionIds.length === 0) {
@@ -138,6 +138,7 @@ import { WorkflowAutomationModule } from '../workflow-automation/workflow-automa
138
138
  ResolverService,
139
139
  EntityDynamicService,
140
140
  'CommonService',
141
+ 'EntityRelationService'
141
142
  ],
142
143
  controllers: [
143
144
  EntityController,
@@ -19,4 +19,31 @@ export class EntityRelationService extends EntityServiceImpl {
19
19
 
20
20
  return relations;
21
21
  }
22
+
23
+ async getRelatedEntityIds(
24
+ sourceEntity: string,
25
+ targetEntity: string,
26
+ targetIds: number[],
27
+ orgId: number,
28
+ ): Promise<number[]> {
29
+
30
+ if (!targetIds.length) return []; // <--- safe guard
31
+
32
+ const result = await this.dataSource.query(
33
+ `
34
+ SELECT DISTINCT source_entity_id
35
+ FROM cr_entity_relation_data
36
+ WHERE source_entity_type = ?
37
+ AND target_entity_type = ?
38
+ AND target_entity_id IN (?)
39
+ AND organization_id = ?
40
+ `,
41
+ [sourceEntity, targetEntity, targetIds, orgId],
42
+ );
43
+
44
+ return result.map((r) => r.source_entity_id);
45
+ }
46
+
47
+
48
+
22
49
  }