rez_core 3.1.21 → 3.1.23

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.21",
3
+ "version": "3.1.23",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -456,42 +456,56 @@ export class FilterService {
456
456
  if (tabs?.columnName && tabs?.value) {
457
457
  const tabAttrMeta = attributeMetaMap[tabs.columnName];
458
458
  const tabValue = tabs.value.toLowerCase();
459
-
459
+
460
460
  if (tabValue === 'others') {
461
+ // existing 'others' logic
461
462
  const valuesToExclude = showList.filter((v) => v !== 'all');
462
463
  if (valuesToExclude.length > 0) {
463
- valuesToExclude.forEach((value) => {
464
- const tabCondition = this.buildCondition(
465
- {
466
- filter_attribute: tabs.columnName,
467
- filter_operator: 'not_equal',
468
- filter_value: [value],
469
- skip_id: true,
470
- },
471
- tabAttrMeta,
464
+ for (const value of valuesToExclude) {
465
+ const resolvedId = await this.resolverService.getResolvedId(
466
+ loggedInUser,
467
+ tabs.columnName,
468
+ value,
469
+ entity_type,
472
470
  );
473
- if (tabCondition) {
474
- dataWhere.push(tabCondition);
471
+ if (resolvedId) {
472
+ const tabCondition = this.buildCondition(
473
+ {
474
+ filter_attribute: tabs.columnName,
475
+ filter_operator: 'not_equal',
476
+ filter_value: [resolvedId],
477
+ skip_id: true,
478
+ },
479
+ tabAttrMeta,
480
+ );
481
+ if (tabCondition) dataWhere.push(tabCondition);
475
482
  }
476
- });
483
+ }
477
484
  }
478
485
  } else if (tabValue !== 'all') {
479
- // Normal case: filter by equality
480
- const tabCondition = this.buildCondition(
481
- {
482
- filter_attribute: tabs.columnName,
483
- filter_operator: 'equal',
484
- filter_value: [tabs.value],
485
- skip_id: true,
486
- },
487
- tabAttrMeta,
486
+ // normal tab case
487
+ const resolvedId = await this.resolverService.getResolvedId(
488
+ loggedInUser,
489
+ tabs.columnName,
490
+ tabs.value,
491
+ entity_type,
488
492
  );
489
-
490
- if (tabCondition) {
491
- dataWhere.push(tabCondition);
493
+
494
+ if (resolvedId) {
495
+ const tabCondition = this.buildCondition(
496
+ {
497
+ filter_attribute: tabs.columnName,
498
+ filter_operator: 'equal',
499
+ filter_value: [resolvedId],
500
+ skip_id: true,
501
+ },
502
+ tabAttrMeta,
503
+ );
504
+ if (tabCondition) dataWhere.push(tabCondition);
492
505
  }
493
506
  }
494
507
  }
508
+
495
509
 
496
510
  // Build raw SQL base
497
511
  const qb = this.dataSource
@@ -1,4 +1,5 @@
1
1
  import { Injectable } from '@nestjs/common';
2
+ import { UserData } from 'src/module/user/entity/user.entity';
2
3
  import { DataSource } from 'typeorm';
3
4
 
4
5
  @Injectable()
@@ -194,4 +195,62 @@ export class ResolverService {
194
195
  return rawValue;
195
196
  }
196
197
 
198
+ async getResolvedId(
199
+ loggedInUser: UserData,
200
+ attrKey: string,
201
+ displayValue: any,
202
+ entityType: string,
203
+ ): Promise<any> {
204
+ if (displayValue === null || displayValue === undefined || displayValue === '') {
205
+ return displayValue;
206
+ }
207
+
208
+ // fetch attribute meta
209
+ const [attr] = await this.dataSource.query(
210
+ `SELECT * FROM cr_attribute_master
211
+ WHERE mapped_entity_type = ? AND organization_id = ? AND attribute_key = ?`,
212
+ [entityType, loggedInUser.organization_id, attrKey],
213
+ );
214
+
215
+ if (!attr) return displayValue;
216
+
217
+ // -------- ENTITY data_source_type --------
218
+ if (attr.data_source_type === 'entity') {
219
+ const [entityDef] = await this.dataSource.query(
220
+ `SELECT * FROM cr_entity_master
221
+ WHERE mapped_entity_type = ? AND organization_id = ?`,
222
+ [attr.datasource_list, loggedInUser.organization_id],
223
+ );
224
+
225
+ if (!entityDef) return displayValue;
226
+
227
+ const tableName = entityDef.db_table_name;
228
+
229
+ const query =
230
+ tableName === 'cr_organization'
231
+ ? `SELECT id FROM ${tableName} WHERE ${attr.data_source_attribute} = ?`
232
+ : `SELECT id FROM ${tableName} WHERE ${attr.data_source_attribute} = ? AND organization_id = ?`;
233
+
234
+ const params =
235
+ tableName === 'cr_organization'
236
+ ? [displayValue]
237
+ : [displayValue, loggedInUser.organization_id];
238
+
239
+ const [item] = await this.dataSource.query(query, params);
240
+ return item?.id ?? displayValue;
241
+ }
242
+
243
+ // -------- MASTER data_source_type --------
244
+ else if (attr.data_source_type === 'master') {
245
+ const [item] = await this.dataSource.query(
246
+ `SELECT id FROM cr_list_master_items
247
+ WHERE ${attr.data_source_attribute} = ? AND organization_id = ?`,
248
+ [displayValue, loggedInUser.organization_id],
249
+ );
250
+ return item?.id ?? displayValue;
251
+ }
252
+
253
+ return displayValue;
254
+ }
255
+
197
256
  }