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/dist/module/filter/service/filter.service.d.ts +3 -1
- package/dist/module/filter/service/filter.service.js +16 -5
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/meta/entity.module.js +1 -0
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/service/entity-relation.service.d.ts +1 -0
- package/dist/module/meta/service/entity-relation.service.js +13 -0
- package/dist/module/meta/service/entity-relation.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +22 -4
- package/src/module/meta/entity.module.ts +1 -0
- package/src/module/meta/service/entity-relation.service.ts +27 -0
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
118
|
-
const
|
|
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
|
-
?
|
|
124
|
-
: intersectionIds.filter((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) {
|
|
@@ -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
|
}
|