rez_core 3.1.19 → 3.1.21

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.19",
3
+ "version": "3.1.21",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -12,7 +12,7 @@ import { FilterEvaluatorService } from './service/filter-evaluator.service';
12
12
  @Module({
13
13
  imports: [
14
14
  TypeOrmModule.forFeature([SavedFilterDetail, SavedFilterMaster]),
15
- forwardRef(() => EntityModule),
15
+ forwardRef(() => EntityModule)
16
16
  ],
17
17
  controllers: [FilterController],
18
18
  providers: [
@@ -9,6 +9,7 @@ import { SavedFilterService } from './saved-filter.service';
9
9
 
10
10
  import * as moment from 'moment';
11
11
  import { EntityRelationService } from 'src/module/meta/service/entity-relation.service';
12
+ import { ResolverService } from 'src/module/meta/service/resolver.service';
12
13
 
13
14
  @Injectable()
14
15
  export class FilterService {
@@ -20,6 +21,7 @@ export class FilterService {
20
21
  private readonly savedFilterService: SavedFilterService,
21
22
  @Inject('EntityRelationService')
22
23
  private readonly entityRelationService: EntityRelationService,
24
+ private readonly resolverService: ResolverService,
23
25
  ) {}
24
26
  private readonly skipAppCodeFilterEntities = ['ORGP'];
25
27
  private readonly skipOrgFilterEntities = ['ORGP'];
@@ -576,6 +578,38 @@ export class FilterService {
576
578
  // 4. Final transformation
577
579
  const formattedEntityList = entity_list.map(formatDatesInRow);
578
580
 
581
+ // 5. Resolve reference values using ResolverService
582
+ const resolvedEntityList = await Promise.all(
583
+ formattedEntityList.map((row) =>
584
+ this.resolverService.getResolvedData(loggedInUser, row, entity_type),
585
+ ),
586
+ );
587
+
588
+
589
+ // 6. Resolve tab values (tab_value field)
590
+ const resolvedTabs = await Promise.all(
591
+ filteredTabs.map(async (tab) => {
592
+ // pick attribute used for tabs
593
+ const tabAttrKey = layout?.attribute || tabs?.columnName;
594
+
595
+ if (!tabAttrKey || tab.tab_value?.toLowerCase() === 'all' || tab.tab_value?.toLowerCase() === 'others') {
596
+ return tab; // skip special cases
597
+ }
598
+
599
+ const resolvedVal = await this.resolverService.getResolvedValue(
600
+ loggedInUser,
601
+ tabAttrKey,
602
+ tab.tab_value,
603
+ entity_type,
604
+ );
605
+
606
+ return {
607
+ ...tab,
608
+ tab_value: resolvedVal ?? tab.tab_value,
609
+ };
610
+ }),
611
+ );
612
+
579
613
  // Count query (without pagination)
580
614
  const countQb = this.dataSource
581
615
  .createQueryBuilder()
@@ -590,8 +624,8 @@ export class FilterService {
590
624
  return {
591
625
  success: true,
592
626
  data: {
593
- entity_tabs: filteredTabs,
594
- entity_list: formattedEntityList,
627
+ entity_tabs: resolvedTabs,
628
+ entity_list: resolvedEntityList,
595
629
  pagination: {
596
630
  total,
597
631
  page,
@@ -3,7 +3,9 @@ import { DataSource } from 'typeorm';
3
3
 
4
4
  @Injectable()
5
5
  export class ResolverService {
6
- constructor(private readonly dataSource: DataSource) {}
6
+ constructor(private readonly dataSource: DataSource,
7
+
8
+ ) {}
7
9
 
8
10
  async getResolvedData(
9
11
  loggedInUser: any,
@@ -105,4 +107,91 @@ export class ResolverService {
105
107
 
106
108
  return resolvedEntityData;
107
109
  }
110
+
111
+ async getResolvedValue(
112
+ loggedInUser: UserData,
113
+ attrKey: string,
114
+ rawValue: any,
115
+ entityType: string,
116
+ ): Promise<any> {
117
+ if (rawValue === null || rawValue === undefined || rawValue === '') {
118
+ return rawValue;
119
+ }
120
+
121
+ // fetch attribute meta only for the given attributeKey
122
+ const [attr] = await this.dataSource.query(
123
+ `SELECT * FROM cr_attribute_master WHERE mapped_entity_type = ? AND organization_id = ? AND attribute_key = ?`,
124
+ [entityType, loggedInUser.organization_id, attrKey],
125
+ );
126
+
127
+ if (!attr) return rawValue;
128
+
129
+ // -------- ENTITY data_source_type --------
130
+ if (attr.data_source_type === 'entity') {
131
+ const [entityDef] = await this.dataSource.query(
132
+ `SELECT * FROM cr_entity_master WHERE mapped_entity_type = ? AND organization_id = ?`,
133
+ [attr.datasource_list, loggedInUser.organization_id],
134
+ );
135
+
136
+ if (!entityDef) return rawValue;
137
+
138
+ const tableName = entityDef.db_table_name;
139
+
140
+ if (Array.isArray(rawValue)) {
141
+ const resolvedValues: string[] = [];
142
+ for (const code of rawValue) {
143
+ const query =
144
+ tableName === 'cr_organization'
145
+ ? `SELECT * FROM ${tableName} WHERE code = ?`
146
+ : `SELECT * FROM ${tableName} WHERE id = ? AND organization_id = ?`;
147
+
148
+ const params =
149
+ tableName === 'cr_organization'
150
+ ? [code]
151
+ : [code, loggedInUser.organization_id];
152
+
153
+ const [item] = await this.dataSource.query(query, params);
154
+ resolvedValues.push(item?.[attr.data_source_attribute] ?? code);
155
+ }
156
+ return resolvedValues;
157
+ } else {
158
+ const query =
159
+ tableName === 'cr_organization'
160
+ ? `SELECT * FROM ${tableName} WHERE id = ?`
161
+ : `SELECT * FROM ${tableName} WHERE id = ? AND organization_id = ?`;
162
+
163
+ const params =
164
+ tableName === 'cr_organization'
165
+ ? [rawValue]
166
+ : [rawValue, loggedInUser.organization_id];
167
+
168
+ const [item] = await this.dataSource.query(query, params);
169
+ return item?.[attr.data_source_attribute] ?? rawValue;
170
+ }
171
+ }
172
+
173
+ // -------- MASTER data_source_type --------
174
+ else if (attr.data_source_type === 'master') {
175
+ if (Array.isArray(rawValue)) {
176
+ const resolvedValues: string[] = [];
177
+ for (const code of rawValue) {
178
+ const [item] = await this.dataSource.query(
179
+ `SELECT * FROM cr_list_master_items WHERE id = ? AND organization_id = ?`,
180
+ [code, loggedInUser.organization_id],
181
+ );
182
+ resolvedValues.push(item?.[attr.data_source_attribute] ?? code);
183
+ }
184
+ return resolvedValues;
185
+ } else {
186
+ const [item] = await this.dataSource.query(
187
+ `SELECT * FROM cr_list_master_items WHERE id = ? AND organization_id = ?`,
188
+ [rawValue, loggedInUser.organization_id],
189
+ );
190
+ return item?.[attr.data_source_attribute] ?? rawValue;
191
+ }
192
+ }
193
+
194
+ return rawValue;
195
+ }
196
+
108
197
  }