rez_core 4.0.73 → 4.0.74

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": "4.0.73",
3
+ "version": "4.0.74",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -218,7 +218,11 @@ export class EntityDynamicService {
218
218
  id: number | string,
219
219
  loggedInUser: any,
220
220
  ): Promise<any> {
221
- const mainEntity = await this.getEntity(entityType, id, loggedInUser);
221
+ const mainEntity = await this.getEntityByDataSource(
222
+ entityType,
223
+ id,
224
+ loggedInUser,
225
+ );
222
226
 
223
227
  const relatedEntities = await this.dataSource.query(
224
228
  `SELECT * FROM frm_entity_relation_data WHERE source_entity_id = ? AND target_entity_type IN (
@@ -536,6 +540,55 @@ export class EntityDynamicService {
536
540
  return result;
537
541
  }
538
542
 
543
+ async getEntityByDataSource(
544
+ entityType: string,
545
+ id: number | string,
546
+ loggedInUser: any,
547
+ ): Promise<any> {
548
+ const organizationId = loggedInUser.organization_id;
549
+
550
+ const dataSource = await this.getEntitySourceTableName(
551
+ entityType,
552
+ organizationId,
553
+ );
554
+ const validAttributes = await this.getAttributeCodes(
555
+ entityType,
556
+ organizationId,
557
+ );
558
+
559
+ const columns = validAttributes
560
+ .map((attr) => `\`${attr.attribute_key}\``)
561
+ .join(', ');
562
+ const selectQuery = `SELECT ${columns} FROM \`${dataSource}\` WHERE id = ?`;
563
+
564
+ const result = await this.dataSource.query(selectQuery, [id]);
565
+ if (!result.length) return null;
566
+
567
+ const row = result[0];
568
+
569
+ // Convert boolean columns (1/0) into true/false
570
+ for (const attr of validAttributes) {
571
+ if (
572
+ attr.db_datatype == 'boolean' &&
573
+ row[attr.attribute_key] !== undefined
574
+ ) {
575
+ row[attr.attribute_key] = row[attr.attribute_key] == 1 ? true : false;
576
+ } else if (
577
+ attr.element_type == 'upload' &&
578
+ row[attr.attribute_key] !== undefined
579
+ ) {
580
+ row[attr.attribute_key] =
581
+ row[attr.attribute_key] != null
582
+ ? await this.mediaDataService.getMediaDownloadUrl(
583
+ Number(row[attr.attribute_key]),
584
+ loggedInUser,
585
+ )
586
+ : null;
587
+ }
588
+ }
589
+
590
+ return row;
591
+ }
539
592
  // -----------------------------
540
593
  async getEntity(
541
594
  entityType: string,
@@ -545,6 +598,10 @@ export class EntityDynamicService {
545
598
  const organizationId = loggedInUser.organization_id;
546
599
 
547
600
  const tableName = await this.getTableName(entityType, organizationId);
601
+ const dataSource = await this.getEntitySourceTableName(
602
+ entityType,
603
+ organizationId,
604
+ );
548
605
  const validAttributes = await this.getAttributeCodes(
549
606
  entityType,
550
607
  organizationId,
@@ -571,13 +628,6 @@ export class EntityDynamicService {
571
628
  attr.element_type == 'upload' &&
572
629
  row[attr.attribute_key] !== undefined
573
630
  ) {
574
- // fetch media data
575
- // console.log(
576
- // 'Fetching media for',
577
- // attr.attribute_key,
578
- // row[attr.attribute_key],
579
- // );
580
-
581
631
  row[attr.attribute_key] =
582
632
  row[attr.attribute_key] != null
583
633
  ? await this.mediaDataService.getMediaDownloadUrl(
@@ -585,14 +635,27 @@ export class EntityDynamicService {
585
635
  loggedInUser,
586
636
  )
587
637
  : null;
588
-
589
- // console.log('Fetched media:', row[attr.attribute_key]);
590
638
  }
591
639
  }
592
640
 
593
641
  return row;
594
642
  }
595
643
 
644
+ private async getEntitySourceTableName(
645
+ entityType: string,
646
+ organizationId: string,
647
+ ): Promise<string> {
648
+ const result = await this.dataSource.query(
649
+ `SELECT data_source, db_table_name FROM frm_entity_master WHERE organization_id = ? AND mapped_entity_type = ?`,
650
+ [organizationId, entityType],
651
+ );
652
+ if (!result.length) {
653
+ console.log(`Entity type '${entityType}' not found in frm_entity_master`);
654
+ }
655
+
656
+ return result[0].data_source;
657
+ }
658
+
596
659
  // -----------------------------
597
660
  private async getTableName(
598
661
  entityType: string,
@@ -64,7 +64,11 @@ export class LoginService {
64
64
  user.status != resolveStatus.id ||
65
65
  userOrgData?.status != resolveStatus.id
66
66
  ) {
67
- throw new BadRequestException('User is inactive.');
67
+ return {
68
+ success: false,
69
+ message:
70
+ 'Your account or organization is inactive. Please contact admin.',
71
+ };
68
72
  }
69
73
 
70
74
  // 🔹 Step 4: Verify password if not OTP