rez_core 4.0.223 → 5.0.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": "4.0.223",
3
+ "version": "5.0.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -15,14 +15,17 @@ export class EntityMasterRepository {
15
15
  @Inject('ListMasterService')
16
16
  private readonly listMasterService: ListMasterService,
17
17
  @InjectRepository(EntityRelation)
18
- private readonly entityRelationRepo: Repository<EntityRelation>
19
- ) {}
18
+ private readonly entityRelationRepo: Repository<EntityRelation>,
19
+ ) {
20
+ }
20
21
 
21
22
  async getEntityById(id: number): Promise<EntityMaster | null> {
22
23
  let data = await this.entityMasterRepository.findOne({ where: { id } });
23
24
  if (data) {
24
25
  let listMasterData = await this.entityMasterRepository.query(
25
- `SELECT * FROM frm_list_master_items where id = $1`,
26
+ `SELECT *
27
+ FROM frm_list_master_items
28
+ where id = $1`,
26
29
  [data?.status],
27
30
  );
28
31
  data.status = listMasterData?.[0].name;
@@ -30,35 +33,40 @@ export class EntityMasterRepository {
30
33
  return data;
31
34
  }
32
35
 
33
- async getAllEntityDropdownData(entity_type:string,loggedInUser) : Promise<{ label: string; value: any }[]> {
34
-
36
+ async getAllEntityDropdownData(entity_type: string, loggedInUser): Promise<{ label: string; value: any }[]> {
35
37
 
36
38
 
37
- let relations = await this.entityRelationRepo
38
- .createQueryBuilder('rel')
39
- .select([
40
- 'rel.name AS label',
41
- 'rel.target_entity_type AS value',
42
- ])
43
- .where('rel.source_entity_type = :entityType', { entityType: entity_type })
44
- .andWhere('rel.organization_id = :orgId', { orgId: loggedInUser.organization_id })
45
- .getRawMany();
39
+ let relations = await this.entityRelationRepo
40
+ .createQueryBuilder('rel')
41
+ .select([
42
+ 'rel.name AS label',
43
+ 'rel.target_entity_type AS value',
44
+ ])
45
+ .where('rel.source_entity_type = :entityType', { entityType: entity_type })
46
+ .andWhere('rel.organization_id = :orgId', { orgId: loggedInUser.organization_id })
47
+ .getRawMany();
46
48
 
47
- // console.log(relations,"-------------")
48
- let parentEntityLabelName = await this.entityMasterRepository.findOne({where:{organization_id: loggedInUser.organization_id,mapped_entity_type:entity_type}});
49
- let dropdownData :any[]=[...relations];
50
- if(parentEntityLabelName) {
51
- dropdownData.push({label:parentEntityLabelName.name,value:entity_type
52
- });
53
- }
49
+ // console.log(relations,"-------------")
50
+ let parentEntityLabelName = await this.entityMasterRepository.findOne({
51
+ where: {
52
+ organization_id: loggedInUser.organization_id,
53
+ mapped_entity_type: entity_type,
54
+ },
55
+ });
56
+ let dropdownData: any[] = [...relations];
57
+ if (parentEntityLabelName) {
58
+ dropdownData.push({
59
+ label: parentEntityLabelName.name, value: entity_type,
60
+ });
61
+ }
54
62
 
55
- return dropdownData.length ? dropdownData:[];
56
- }
63
+ return dropdownData.length ? dropdownData : [];
64
+ }
57
65
 
58
66
 
59
67
  async getEntityByMappedEntityType(
60
68
  mappedEntityType: string,
61
- organizationId: number,
69
+ organizationId: any,
62
70
  ): Promise<EntityMaster | null> {
63
71
  return await this.entityMasterRepository.findOne({
64
72
  where: {
@@ -85,7 +93,11 @@ return dropdownData.length ? dropdownData:[];
85
93
  const organization_id = loggedInUser.organization_id;
86
94
 
87
95
  const attributes = await this.dataSource.query(
88
- `SELECT * FROM frm_entity_attribute WHERE mapped_entity_type = $1 AND data_type = 'DATE' AND organization_id = $2`,
96
+ `SELECT *
97
+ FROM frm_entity_attribute
98
+ WHERE mapped_entity_type = $1
99
+ AND data_type = 'DATE'
100
+ AND organization_id = $2`,
89
101
  [entity_type, organization_id],
90
102
  );
91
103
 
@@ -1,5 +1,5 @@
1
1
  import { level } from 'winston';
2
- import { Injectable } from '@nestjs/common';
2
+ import { BadRequestException, Injectable } from '@nestjs/common';
3
3
  import {
4
4
  ENTITYTYPE_ENTITYMASTER,
5
5
  STATUS_ACTIVE,
@@ -9,6 +9,8 @@ import { UserData } from 'src/module/user/entity/user.entity';
9
9
  import { MediaDataService } from './media-data.service';
10
10
  import { ResolverService } from './resolver.service';
11
11
  import { ConfigService } from '@nestjs/config';
12
+ import { EntityMasterService } from './entity-master.service';
13
+ import { EntityMasterRepository } from '../repository/entity-master.repository';
12
14
 
13
15
  @Injectable()
14
16
  export class EntityDynamicService {
@@ -17,6 +19,7 @@ export class EntityDynamicService {
17
19
  private readonly mediaDataService: MediaDataService,
18
20
  private readonly resolverService: ResolverService,
19
21
  private readonly configService: ConfigService,
22
+ private readonly entityMasterRepo: EntityMasterRepository,
20
23
  ) {}
21
24
 
22
25
  // -----------------------------
@@ -649,15 +652,14 @@ export class EntityDynamicService {
649
652
  organizationId: string,
650
653
  ): Promise<string> {
651
654
 
652
- const result = await this.queryWithSchema(`SELECT data_source, db_table_name FROM frm_entity_master WHERE organization_id = $1 AND mapped_entity_type = $2`,
653
- [organizationId, entityType]
654
- );
655
+ const result = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, organizationId);
655
656
 
656
- if (!result.length) {
657
+ if (!result) {
657
658
  console.log(`Entity type '${entityType}' not found in frm_entity_master`);
659
+ throw new BadRequestException();
658
660
  }
659
661
 
660
- return result[0].data_source;
662
+ return result.data_source;
661
663
  }
662
664
 
663
665
  // -----------------------------
@@ -50,34 +50,35 @@ export class EntityRelationService extends EntityServiceImpl {
50
50
  if (!targetIds.length) return [];
51
51
 
52
52
  let paramIndex = 1;
53
+ const params: any[] = [];
53
54
 
54
- // first three params
55
- const params: any[] = [
56
- String(sourceEntity), // $1
57
- String(targetEntity), // $2
58
- ];
55
+ // $1 and $2 are text (entity types)
56
+ params.push(sourceEntity); // do NOT convert to string, pg will treat as text
57
+ const sourceEntityParam = `$${paramIndex++}`;
59
58
 
60
- // build placeholders for targetIds
59
+ params.push(targetEntity);
60
+ const targetEntityParam = `$${paramIndex++}`;
61
+
62
+ // Build placeholders for IDs → IDs must remain NUMBER
61
63
  const idPlaceholders = targetIds
62
64
  .map((id) => {
63
- params.push(String(id));
64
- paramIndex++;
65
- return `$${paramIndex}`;
65
+ params.push(Number(id)); // ✔ FIX: Use Number
66
+ return `$${paramIndex++}`;
66
67
  })
67
68
  .join(", ");
68
69
 
69
- // now orgId
70
- params.push(String(orgId));
71
- paramIndex++;
70
+ // org id
71
+ params.push(Number(orgId)); // ✔ FIX: Use Number
72
+ const orgPlaceholder = `$${paramIndex}`;
72
73
 
73
74
  const sql = `
74
- SELECT DISTINCT source_entity_id
75
- FROM frm_entity_relation_data
76
- WHERE source_entity_type = $1
77
- AND target_entity_type = $2
78
- AND target_entity_id IN (${idPlaceholders})
79
- AND organization_id = $${paramIndex}
80
- `;
75
+ SELECT DISTINCT source_entity_id
76
+ FROM frm_entity_relation_data
77
+ WHERE source_entity_type = ${sourceEntityParam}
78
+ AND target_entity_type = ${targetEntityParam}
79
+ AND target_entity_id IN (${idPlaceholders})
80
+ AND organization_id = ${orgPlaceholder}
81
+ `;
81
82
 
82
83
  const rows = await this.dataSource.query(sql, params);
83
84