rez_core 5.0.85 → 5.0.86

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.
Files changed (81) hide show
  1. package/.idea/250218_nodejs_core.iml +12 -0
  2. package/.idea/codeStyles/Project.xml +59 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/prettier.xml +6 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/dist/module/auth/services/auth.service.d.ts +3 -3
  9. package/dist/module/auth/services/auth.service.js +18 -7
  10. package/dist/module/auth/services/auth.service.js.map +1 -1
  11. package/dist/module/dashboard/controller/dashboard.controller.d.ts +1 -1
  12. package/dist/module/dashboard/repository/dashboard.repository.d.ts +5 -4
  13. package/dist/module/dashboard/repository/dashboard.repository.js +31 -18
  14. package/dist/module/dashboard/repository/dashboard.repository.js.map +1 -1
  15. package/dist/module/dashboard/service/dashboard.service.d.ts +1 -1
  16. package/dist/module/filter/filter.module.js +2 -0
  17. package/dist/module/filter/filter.module.js.map +1 -1
  18. package/dist/module/filter/repository/saved-filter.repository.d.ts +4 -3
  19. package/dist/module/filter/repository/saved-filter.repository.js +11 -8
  20. package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
  21. package/dist/module/filter/repository/saved.filter-detail.repository.d.ts +7 -0
  22. package/dist/module/filter/repository/saved.filter-detail.repository.js +38 -0
  23. package/dist/module/filter/repository/saved.filter-detail.repository.js.map +1 -0
  24. package/dist/module/filter/service/filter-evaluator.service.d.ts +3 -3
  25. package/dist/module/filter/service/filter-evaluator.service.js +6 -9
  26. package/dist/module/filter/service/filter-evaluator.service.js.map +1 -1
  27. package/dist/module/filter/service/filter.service.d.ts +5 -3
  28. package/dist/module/filter/service/filter.service.js +27 -17
  29. package/dist/module/filter/service/filter.service.js.map +1 -1
  30. package/dist/module/integration/service/wrapper.service.d.ts +3 -7
  31. package/dist/module/integration/service/wrapper.service.js +71 -69
  32. package/dist/module/integration/service/wrapper.service.js.map +1 -1
  33. package/dist/module/listmaster/repository/list-master.repository.d.ts +1 -0
  34. package/dist/module/listmaster/repository/list-master.repository.js +9 -0
  35. package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
  36. package/dist/module/listmaster/service/list-master-item.service.d.ts +2 -1
  37. package/dist/module/listmaster/service/list-master-item.service.js +3 -5
  38. package/dist/module/listmaster/service/list-master-item.service.js.map +1 -1
  39. package/dist/module/meta/repository/attribute-master.repository.d.ts +5 -3
  40. package/dist/module/meta/repository/attribute-master.repository.js +28 -8
  41. package/dist/module/meta/repository/attribute-master.repository.js.map +1 -1
  42. package/dist/module/meta/service/entity-dynamic.service.d.ts +3 -5
  43. package/dist/module/meta/service/entity-dynamic.service.js +42 -48
  44. package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
  45. package/dist/module/meta/service/media-data.service.d.ts +3 -3
  46. package/dist/module/meta/service/media-data.service.js +37 -16
  47. package/dist/module/meta/service/media-data.service.js.map +1 -1
  48. package/dist/module/module/repository/menu.repository.d.ts +3 -1
  49. package/dist/module/module/repository/menu.repository.js +33 -31
  50. package/dist/module/module/repository/menu.repository.js.map +1 -1
  51. package/dist/module/workflow/repository/comm-template.repository.d.ts +3 -1
  52. package/dist/module/workflow/repository/comm-template.repository.js +12 -6
  53. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  54. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  55. package/dist/tsconfig.build.tsbuildinfo +1 -1
  56. package/package.json +1 -1
  57. package/src/module/auth/services/auth.service.ts +17 -11
  58. package/src/module/dashboard/repository/dashboard.repository.ts +28 -19
  59. package/src/module/filter/filter.module.ts +2 -0
  60. package/src/module/filter/repository/saved-filter.repository.ts +22 -22
  61. package/src/module/filter/repository/saved.filter-detail.repository.ts +20 -0
  62. package/src/module/filter/service/filter-evaluator.service.ts +6 -10
  63. package/src/module/filter/service/filter.service.ts +24 -19
  64. package/src/module/integration/service/wrapper.service.ts +81 -103
  65. package/src/module/listmaster/repository/list-master.repository.ts +10 -0
  66. package/src/module/listmaster/service/list-master-item.service.ts +4 -15
  67. package/src/module/meta/repository/attribute-master.repository.ts +30 -12
  68. package/src/module/meta/service/entity-dynamic.service.ts +58 -69
  69. package/src/module/meta/service/media-data.service.ts +43 -40
  70. package/src/module/module/repository/menu.repository.ts +33 -40
  71. package/src/module/workflow/repository/comm-template.repository.ts +10 -8
  72. package/src/module/workflow/service/workflow-meta.service.ts +0 -21
  73. package/.vscode/extensions.json +0 -5
  74. package/dist/module/dev/dev.module.d.ts +0 -2
  75. package/dist/module/dev/dev.module.js +0 -25
  76. package/dist/module/dev/dev.module.js.map +0 -1
  77. package/dist/module/dev/service/dev.service.d.ts +0 -5
  78. package/dist/module/dev/service/dev.service.js +0 -25
  79. package/dist/module/dev/service/dev.service.js.map +0 -1
  80. package/src/module/dev/dev.module.ts +0 -12
  81. package/src/module/dev/service/dev.service.ts +0 -7
@@ -1,23 +1,18 @@
1
1
  import { Injectable, Logger } from '@nestjs/common';
2
- import { DataSource } from 'typeorm';
3
2
  import { GenericMessageDto, IntegrationService } from './integration.service';
4
- import { GoogleService } from './calendar-event.service';
5
3
  import { IcsMeetingService } from 'src/module/ics/service/ics.service';
6
4
  import { LoggingService } from 'src/utils/service/loggingUtil.service';
7
- import { MediaDataService } from 'src/module/meta/service/media-data.service';
8
- import axios from 'axios';
5
+ import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
9
6
 
10
7
  @Injectable()
11
8
  export class WrapperService {
12
9
  private readonly logger = new Logger(WrapperService.name);
13
10
 
14
11
  constructor(
15
- private readonly datasource: DataSource,
16
12
  private readonly integrationService: IntegrationService,
17
- private readonly googleService: GoogleService,
18
13
  private readonly icsService: IcsMeetingService,
19
14
  private readonly loggingService: LoggingService,
20
- private readonly mediaService: MediaDataService,
15
+ private readonly reflectionHelper: ReflectionHelper,
21
16
  ) {}
22
17
 
23
18
  /**
@@ -47,14 +42,16 @@ export class WrapperService {
47
42
  [],
48
43
  [],
49
44
  );
50
- const configs = await this.datasource.query(
51
- `SELECT * FROM frm_integration_config
52
- WHERE level_id = $1
53
- AND level_type = $2
54
- AND status = 1
55
- AND integration_type = 'EMAIL'`,
56
- [level_id, level_type],
57
- );
45
+ const intergrationConfigRepo =
46
+ this.reflectionHelper.getRepoService('IntegrationConfig');
47
+ const configs = await intergrationConfigRepo.find({
48
+ where: {
49
+ level_id: level_id,
50
+ level_type: level_type,
51
+ status: 1,
52
+ integration_type: 'EMAIL',
53
+ },
54
+ });
58
55
 
59
56
  this.loggingService.log(
60
57
  'debug',
@@ -77,10 +74,17 @@ export class WrapperService {
77
74
  [],
78
75
  );
79
76
 
80
- const template = await this.datasource.query(
81
- `SELECT rich_text FROM frm_wf_comm_template WHERE code = $1 AND level_id = $2 AND level_type = $3 LIMIT 1`,
82
- [payload.templateCode, level_id, level_type],
83
- );
77
+ const templateRepo =
78
+ this.reflectionHelper.getRepoService('CommTemplate');
79
+
80
+ const template = await templateRepo.findOne({
81
+ where: {
82
+ code: payload.templateCode,
83
+ level_id: level_id,
84
+ level_type: level_type,
85
+ },
86
+ });
87
+
84
88
  this.loggingService.log(
85
89
  'debug',
86
90
  'wrapperService',
@@ -90,8 +94,8 @@ export class WrapperService {
90
94
  [],
91
95
  );
92
96
 
93
- if (template && template.length > 0) {
94
- templateCode = template[0]?.rich_text;
97
+ if (template) {
98
+ templateCode = template.rich_text;
95
99
  } else {
96
100
  this.loggingService.log(
97
101
  'warn',
@@ -142,12 +146,13 @@ export class WrapperService {
142
146
  [],
143
147
  );
144
148
 
145
- const fallbackConfigs = await this.datasource.query(
146
- `SELECT * FROM frm_integration_config
147
- WHERE level_type = 'ORG'
148
- AND integration_type = 'EMAIL'
149
- AND status = 1`,
150
- );
149
+ const fallbackConfigs = await intergrationConfigRepo.find({
150
+ where: {
151
+ level_type: 'ORG',
152
+ integration_type: 'EMAIL',
153
+ status: 1,
154
+ },
155
+ });
151
156
 
152
157
  this.loggingService.log(
153
158
  'debug',
@@ -319,14 +324,15 @@ export class WrapperService {
319
324
  );
320
325
 
321
326
  // Try to find template at user's level first
322
- let templates = await this.datasource.query(
323
- `SELECT id FROM frm_wf_comm_template
324
- WHERE code = $1
325
- AND level_id = $2
326
- AND level_type = $3
327
- LIMIT 1`,
328
- [entity.template_code, level_id, level_type],
329
- );
327
+ const commTemplateRepo =
328
+ this.reflectionHelper.getRepoService('CommTemplate');
329
+ let templates = await commTemplateRepo.find({
330
+ where: {
331
+ code: entity.template_code,
332
+ level_id: level_id,
333
+ level_type: level_type,
334
+ },
335
+ });
330
336
 
331
337
  // Fallback to ORG + organization_id if not found
332
338
  if (!templates || templates.length === 0) {
@@ -339,14 +345,12 @@ export class WrapperService {
339
345
  [],
340
346
  );
341
347
 
342
- templates = await this.datasource.query(
343
- `SELECT id FROM frm_wf_comm_template
344
- WHERE code = $1
345
- AND level_type = 'ORG'
346
- AND organization_id = $2
347
- LIMIT 1`,
348
- [entity.template_code, organization_id],
349
- );
348
+ templates = await commTemplateRepo.find({
349
+ where: {
350
+ code: entity.template_code,
351
+ organization_id: organization_id,
352
+ },
353
+ });
350
354
  }
351
355
 
352
356
  if (templates && templates.length > 0) {
@@ -387,45 +391,11 @@ export class WrapperService {
387
391
  user_id: loggedInUser.id,
388
392
  entity_type: entity.entity_type,
389
393
  entity_id: entity.entity_id,
390
- attachments: [],
394
+ attachments: entity.attachments,
391
395
  mediaUrl: entity.mediaUrl,
392
396
  organization_id: organization_id,
393
397
  } as any;
394
398
 
395
- // attachments: [1, 2, 3, 4]
396
-
397
- if (entity.attachments && entity.attachments.length > 0) {
398
- mailPayload.attachments = [];
399
-
400
- for (const attachmentId of entity.attachments) {
401
- // Step 1: Download or get media file
402
- const url = await this.mediaService.getMediaDownloadUrl(
403
- attachmentId,
404
- {},
405
- 60000,
406
- );
407
-
408
- if (!url?.signedUrl) continue;
409
-
410
- // Step 2: Fetch file content
411
- const response = await axios.get(url.signedUrl, {
412
- responseType: 'arraybuffer',
413
- });
414
-
415
- // Step 3: Convert to base64
416
- const base64Content = Buffer.from(response.data).toString('base64');
417
-
418
- // Step 4: Push formatted attachment
419
- mailPayload.attachments.push({
420
- content: base64Content,
421
- type:
422
- response.headers['content-type'] || 'application/octet-stream',
423
- filename: url.fileName,
424
- disposition: 'attachment',
425
- });
426
- }
427
- }
428
-
429
399
  this.loggingService.log(
430
400
  'debug',
431
401
  'wrapperService',
@@ -537,15 +507,18 @@ export class WrapperService {
537
507
  [],
538
508
  );
539
509
 
540
- const orgConfigs = await this.datasource.query(
541
- `SELECT * FROM frm_integration_config
542
- WHERE level_id = 1
543
- AND level_type = 'ORG'
544
- AND integration_type = 'EMAIL'
545
- AND app_code ='DEFAULT'
546
- AND status = 1`,
547
- [],
548
- );
510
+ const integrationConfigRepo =
511
+ this.reflectionHelper.getRepoService('IntegrationConfig');
512
+
513
+ const orgConfigs = await integrationConfigRepo.find({
514
+ where: {
515
+ level_id: 1,
516
+ level_type: 'ORG',
517
+ integration_type: 'EMAIL',
518
+ app_code: 'DEFAULT',
519
+ status: 1,
520
+ },
521
+ });
549
522
 
550
523
  integrationConfig = await this.integrationService.getSingleActiveConfig(
551
524
  1,
@@ -601,12 +574,16 @@ export class WrapperService {
601
574
  [],
602
575
  [],
603
576
  );
604
- const configRes = await this.datasource.query(
605
- `SELECT config_json
606
- FROM frm_integration_config
607
- WHERE id = $1`,
608
- [configId],
609
- );
577
+
578
+ const integrationConfigRepo =
579
+ this.reflectionHelper.getRepoService('IntegrationConfig');
580
+
581
+ const configRes = await integrationConfigRepo.findOne({
582
+ where: {
583
+ id: configId,
584
+ },
585
+ });
586
+
610
587
  this.loggingService.log(
611
588
  'debug',
612
589
  'wrapperService',
@@ -615,7 +592,7 @@ export class WrapperService {
615
592
  [],
616
593
  [],
617
594
  );
618
- return configRes?.[0]?.config_json || null;
595
+ return configRes?.config_json || null;
619
596
  }
620
597
 
621
598
  private async sendIcsInvite(
@@ -636,15 +613,16 @@ export class WrapperService {
636
613
  );
637
614
 
638
615
  if (payload.template_code) {
639
- let templates = await this.datasource.query(
640
- `SELECT id FROM frm_wf_comm_template
641
- WHERE code = $1
642
- AND level_id = $2
643
- AND level_type = $3
644
- LIMIT 1`,
645
- [payload.template_code, levelId, levelType],
646
- );
647
- this.logger.log(`template by code ${JSON.stringify(payload)}`);
616
+ const commTemplateRepo =
617
+ this.reflectionHelper.getRepoService('CommTemplate');
618
+ let templates = await commTemplateRepo.find({
619
+ where: {
620
+ code: payload.template_code,
621
+ level_id: levelId,
622
+ levelType: levelType,
623
+ },
624
+ });
625
+
648
626
  if (templates && templates.length > 0) {
649
627
  payload['templateId'] = templates[0].id;
650
628
  }
@@ -43,4 +43,14 @@ export class ListMasterRepository {
43
43
 
44
44
  return await qb.getMany();
45
45
  }
46
+
47
+ async findByOrganizationIdAndSource(organization_id, source) {
48
+ return await this.repo
49
+ .createQueryBuilder("lm")
50
+ .select("lm.name", "label")
51
+ .addSelect("lm.type", "value")
52
+ .where("lm.organization_id = :orgId", { orgId: organization_id })
53
+ .andWhere("lm.source = :source", { source })
54
+ .getRawMany();
55
+ }
46
56
  }
@@ -1,22 +1,17 @@
1
1
  import { DataSource } from 'typeorm';
2
- import {
3
- BadRequestException,
4
- forwardRef,
5
- Inject,
6
- Injectable,
7
- NotFoundException,
8
- } from '@nestjs/common';
2
+ import { BadRequestException, forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
9
3
  import { ListMasterItemsRepository } from '../repository/list-master-items.repository';
10
4
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
11
5
  import { UserData } from 'src/module/user/entity/user.entity';
12
6
  import { CodeGeneratorService } from 'src/utils/service/codeGenerator.service';
13
7
  import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
8
+ import { ListMasterRepository } from '../repository/list-master.repository';
14
9
 
15
10
  @Injectable()
16
11
  export class ListMasterItemService extends EntityServiceImpl {
17
12
  constructor(
18
13
  private readonly listItemsRepo: ListMasterItemsRepository,
19
- private readonly listMasterRepo: ListMasterItemsRepository,
14
+ private readonly listMasterRepo: ListMasterRepository,
20
15
  @Inject(forwardRef(() => EntityServiceImpl))
21
16
  private readonly entityServiceImpl: EntityServiceImpl,
22
17
  protected readonly attributeMasterService: AttributeMasterService,
@@ -189,13 +184,7 @@ export class ListMasterItemService extends EntityServiceImpl {
189
184
  loggedInUser: UserData,
190
185
  source: string,
191
186
  ): Promise<any> {
192
- const data = await this.dataSource.query(
193
- `SELECT name AS label, type AS value
194
- FROM frm_list_master
195
- WHERE organization_id = $1 AND source = $2`,
196
- [loggedInUser.organization_id, source],
197
- );
198
- return data;
187
+ return await this.listMasterRepo.findByOrganizationIdAndSource(loggedInUser.organization_id, source);
199
188
  }
200
189
 
201
190
  // async getResolvedListMasterItems(
@@ -1,15 +1,17 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { AttributeMaster } from '../entity/attribute-master.entity';
4
- import { In, Repository, DataSource } from 'typeorm';
4
+ import { EntityManager, Repository } from 'typeorm';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
+ import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
6
7
 
7
8
  @Injectable()
8
9
  export class AttributeMasterRepository {
9
10
  constructor(
10
11
  @InjectRepository(AttributeMaster)
11
12
  private readonly attributeMasterRepository: Repository<AttributeMaster>,
12
- private readonly dataSource: DataSource,
13
+ private readonly entityManger: EntityManager,
14
+ private readonly reflectionHelper: ReflectionHelper,
13
15
  ) {}
14
16
 
15
17
  // ---------- Existing Methods ----------
@@ -101,21 +103,33 @@ return dropdownData;
101
103
  entityType: string,
102
104
  loggedInUser: UserData,
103
105
  ): Promise<string | null> {
104
- const result = await this.dataSource.query(
105
- `SELECT db_table_name FROM frm_entity_master WHERE mapped_entity_type = $1 AND organization_id = $2`,
106
- [entityType, loggedInUser.organization_id],
107
- );
108
- return result.length ? result[0].db_table_name : null;
106
+ const entityMasterRepo = this.reflectionHelper.getRepoService('EntityMaster');
107
+ const result = await entityMasterRepo.findOne({
108
+ where: {
109
+ mapped_entity_type: entityType,
110
+ organization_id: loggedInUser.organization_id,
111
+ },
112
+ });
113
+ if (result) {
114
+ return result.db_table_name;
115
+ }
116
+ return null;
109
117
  }
110
118
 
111
119
  async checkIfColumnExists(
112
120
  tableName: string,
113
121
  columnName: string,
114
122
  ): Promise<boolean> {
115
- const result = await this.dataSource.query(
116
- `SHOW COLUMNS FROM \`${tableName}\` LIKE $1`,
117
- [columnName],
123
+ const result = await this.entityManger.query(
124
+ `
125
+ SELECT column_name
126
+ FROM information_schema.columns
127
+ WHERE table_name = $1
128
+ AND column_name = $2
129
+ `,
130
+ [tableName, columnName],
118
131
  );
132
+
119
133
  return result.length > 0;
120
134
  }
121
135
 
@@ -124,8 +138,12 @@ return dropdownData;
124
138
  columnName: string,
125
139
  columnType: string,
126
140
  ): Promise<void> {
127
- const alterQuery = `ALTER TABLE \`${tableName}\` ADD COLUMN \`${columnName}\` ${columnType} NULL`;
128
- await this.dataSource.query(alterQuery);
141
+ const alterQuery = `
142
+ ALTER TABLE "${tableName}"
143
+ ADD COLUMN IF NOT EXISTS "${columnName}" ${columnType}
144
+ `;
145
+
146
+ await this.entityManger.query(alterQuery);
129
147
  }
130
148
 
131
149
  async findByMappedEntityTypeAndAttributeKeyAndOrganizationId(mapped_entity_type: string, attribute_key: string, organization_id: number) {
@@ -1,20 +1,18 @@
1
1
  import { BadRequestException, Injectable } from '@nestjs/common';
2
2
  import { STATUS_ACTIVE } from 'src/constant/global.constant';
3
- import { DataSource,In } from 'typeorm';
3
+ import { EntityManager, In } from 'typeorm';
4
4
  import { UserData } from 'src/module/user/entity/user.entity';
5
5
  import { MediaDataService } from './media-data.service';
6
6
  import { ResolverService } from './resolver.service';
7
- import { ConfigService } from '@nestjs/config';
8
7
  import { EntityMasterRepository } from '../repository/entity-master.repository';
9
8
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
10
9
 
11
10
  @Injectable()
12
11
  export class EntityDynamicService {
13
12
  constructor(
14
- private readonly dataSource: DataSource,
13
+ private readonly entityManager: EntityManager,
15
14
  private readonly mediaDataService: MediaDataService,
16
15
  private readonly resolverService: ResolverService,
17
- private readonly configService: ConfigService,
18
16
  private readonly entityMasterRepo: EntityMasterRepository,
19
17
  private readonly reflectionHelper: ReflectionHelper,
20
18
  ) {}
@@ -59,15 +57,14 @@ export class EntityDynamicService {
59
57
  // -------------------------------------------------------
60
58
  // STATUS
61
59
  // -------------------------------------------------------
62
- const statusList = await this.dataSource.query(
63
- `
64
- SELECT id
65
- FROM frm_list_master_items
66
- WHERE code = $1
67
- AND organization_id = $2
68
- `,
69
- [STATUS_ACTIVE, organizationId],
70
- );
60
+ const listMasterItemsRepo =
61
+ this.reflectionHelper.getRepoService('ListMasterItems');
62
+ const statusList = listMasterItemsRepo.find({
63
+ where: {
64
+ code: STATUS_ACTIVE,
65
+ organization_id: organizationId,
66
+ },
67
+ });
71
68
 
72
69
  if (!entityData.status) entityData.status = statusList[0]?.id;
73
70
 
@@ -76,7 +73,7 @@ export class EntityDynamicService {
76
73
  // -------------------------------------------------------
77
74
  if (!entityData.code && entityData.entity_type) {
78
75
  // Extract integer suffix
79
- const result = await this.dataSource.query(
76
+ const result = await this.entityManager.query(
80
77
  `
81
78
  SELECT MAX(id) AS max_seq_no
82
79
  FROM ${tableName}
@@ -148,7 +145,7 @@ export class EntityDynamicService {
148
145
  VALUES (${placeholderList}) RETURNING id
149
146
  `;
150
147
 
151
- const result = await this.dataSource.query(sql, values);
148
+ const result = await this.entityManager.query(sql, values);
152
149
  return result[0];
153
150
  }
154
151
 
@@ -162,14 +159,14 @@ export class EntityDynamicService {
162
159
  ): Promise<any> {
163
160
  const organizationId = loggedInUser.organization_id;
164
161
 
165
- const repo = this.reflectionHelper.getRepoService('EntityRelation')
162
+ const repo = this.reflectionHelper.getRepoService('EntityRelation');
166
163
 
167
- const getRelation = await repo.find({
168
- where:{
169
- organization_id:organizationId,
170
- source_entity_type:entityType,
171
- }
172
- })
164
+ const getRelation = await repo.find({
165
+ where: {
166
+ organization_id: organizationId,
167
+ source_entity_type: entityType,
168
+ },
169
+ });
173
170
 
174
171
  // const getRelation = await this.dataSource.query(
175
172
  // `SELECT *
@@ -215,7 +212,8 @@ export class EntityDynamicService {
215
212
  mainID, // this will pass for parent_id
216
213
  );
217
214
 
218
- const relationRepo = this.reflectionHelper.getRepoService('EntityRelationData')
215
+ const relationRepo =
216
+ this.reflectionHelper.getRepoService('EntityRelationData');
219
217
 
220
218
  await relationRepo.save({
221
219
  organizationId: organizationId,
@@ -223,8 +221,8 @@ export class EntityDynamicService {
223
221
  source_entity_type: entityType,
224
222
  target_entity_id: createdRelatedEntity.id,
225
223
  targetEntityType: targetEntityType,
226
- relation_type: relationType
227
- })
224
+ relation_type: relationType,
225
+ });
228
226
 
229
227
  // await this.dataSource.query(
230
228
  // `INSERT INTO frm_entity_relation_data (organization_id, source_entity_id, source_entity_type,
@@ -264,13 +262,14 @@ export class EntityDynamicService {
264
262
  loggedInUser,
265
263
  );
266
264
  const relationRepo = this.reflectionHelper.getRepoService('EntityRelation');
267
- const relatedEntityRepo = this.reflectionHelper.getRepoService('EntityRelationData');
265
+ const relatedEntityRepo =
266
+ this.reflectionHelper.getRepoService('EntityRelationData');
268
267
 
269
268
  const relations = await relationRepo.find({
270
- where: {source_entity_type: entityType}
271
- })
269
+ where: { source_entity_type: entityType },
270
+ });
272
271
 
273
- const targetTypes = relations.map(r=> r.target_entity_type)
272
+ const targetTypes = relations.map((r) => r.target_entity_type);
274
273
 
275
274
  if (targetTypes.length === 0) {
276
275
  return {
@@ -352,13 +351,14 @@ export class EntityDynamicService {
352
351
  const updatedRelations: Record<string, any> = {};
353
352
 
354
353
  if (mappedEntities) {
355
- const getRelationDefs = await this.dataSource.query(
356
- `SELECT *
357
- FROM frm_entity_relation
358
- WHERE organization_id = $1
359
- AND source_entity_type = $2`,
360
- [organizationId, entityType],
361
- );
354
+ const entityRelationRepo =
355
+ this.reflectionHelper.getRepoService('EntityRelation');
356
+ const getRelationDefs = await entityRelationRepo.find({
357
+ where: {
358
+ organization_id: organizationId,
359
+ source_entity_type: entityType,
360
+ },
361
+ });
362
362
 
363
363
  for (const [targetEntityType, rawEntityData] of Object.entries(
364
364
  mappedEntities,
@@ -374,15 +374,6 @@ export class EntityDynamicService {
374
374
  : [rawEntityData];
375
375
 
376
376
  // Delete previous relations and related entities
377
- const existingRelationsForType = await this.dataSource.query(
378
- `SELECT *
379
- FROM frm_entity_relation_data
380
- WHERE source_entity_type = $1
381
- AND source_entity_id = $2
382
- AND target_entity_type = $3`,
383
- [entityType, id, targetEntityType],
384
- );
385
-
386
377
  // Create/update new entities & relations
387
378
  const updatedEntities: any[] = [];
388
379
 
@@ -435,20 +426,16 @@ export class EntityDynamicService {
435
426
  );
436
427
 
437
428
  // Insert relation as per new entity created
438
- await this.dataSource.query(
439
- `INSERT INTO frm_entity_relation_data
440
- (organization_id, source_entity_id, source_entity_type, target_entity_id, target_entity_type,
441
- relation_type)
442
- VALUES ($1, $2, $3, $4, $5, $6)`,
443
- [
444
- organizationId,
445
- id,
446
- entityType,
447
- targetEntityId,
448
- targetEntityType,
449
- relationType,
450
- ],
451
- );
429
+ const entityRelationDataRepo =
430
+ this.reflectionHelper.getRepoService('EntityRelationData');
431
+ await entityRelationDataRepo.save({
432
+ organizationId: organizationId,
433
+ source_entity_id: id,
434
+ source_entity_type: entityType,
435
+ target_entity_id: targetEntityId,
436
+ targetEntityType: targetEntityType,
437
+ relation_type: relationType,
438
+ });
452
439
  }
453
440
 
454
441
  if (relationType === 'ONE_TO_MANY') {
@@ -562,7 +549,7 @@ export class EntityDynamicService {
562
549
  WHERE id = ${idPlaceholder}
563
550
  `;
564
551
 
565
- return await this.dataSource.query(updateQuery, values);
552
+ return await this.entityManager.query(updateQuery, values);
566
553
  }
567
554
 
568
555
  async getEntityByDataSource(
@@ -589,7 +576,7 @@ export class EntityDynamicService {
589
576
  FROM ${dataSource}
590
577
  WHERE id = $1`;
591
578
 
592
- const result = await this.dataSource.query(selectQuery, [id]);
579
+ const result = await this.entityManager.query(selectQuery, [id]);
593
580
  if (!result.length) return null;
594
581
 
595
582
  const row = result[0];
@@ -644,7 +631,7 @@ export class EntityDynamicService {
644
631
  FROM ${tableName} t
645
632
  WHERE id = $1`;
646
633
 
647
- const result = await this.dataSource.query(selectQuery, [id]);
634
+ const result = await this.entityManager.query(selectQuery, [id]);
648
635
  if (!result.length) return null;
649
636
 
650
637
  const row = result[0];
@@ -713,13 +700,15 @@ export class EntityDynamicService {
713
700
  organizationId: string,
714
701
  isHidden = true,
715
702
  ) {
716
- const qb = this.dataSource
717
- .createQueryBuilder()
703
+ const attributeMasterRepo =
704
+ this.reflectionHelper.getRepoService('AttributeMaster');
705
+
706
+ const qb = attributeMasterRepo
707
+ .createQueryBuilder('fea')
718
708
  .select('fea.attribute_key', 'attribute_key')
719
709
  .addSelect('MAX(fea.db_datatype)', 'db_datatype')
720
710
  .addSelect('MAX(fea.element_type)', 'element_type')
721
- .addSelect('BOOL_OR(fea.is_hidden)', 'is_hidden') // ✅ FIXED for Postgres
722
- .from('frm_entity_attribute', 'fea')
711
+ .addSelect('bool_or(fea.is_hidden)', 'is_hidden')
723
712
  .where('fea.mapped_entity_type = :entityType', { entityType })
724
713
  .andWhere('fea.organization_id = :organizationId', { organizationId });
725
714
 
@@ -751,7 +740,7 @@ export class EntityDynamicService {
751
740
  const deleteQuery = `DELETE
752
741
  FROM \`${tableName}\`
753
742
  WHERE id = $1`;
754
- const result = await this.dataSource.query(deleteQuery, [id]);
743
+ const result = await this.entityManager.query(deleteQuery, [id]);
755
744
  return result;
756
745
  }
757
746
 
@@ -773,7 +762,7 @@ export class EntityDynamicService {
773
762
  params.push(appcode);
774
763
  }
775
764
 
776
- const dropdown = await this.dataSource.query(query, params);
765
+ const dropdown = await this.entityManager.query(query, params);
777
766
  return dropdown;
778
767
  }
779
768
 
@@ -796,7 +785,7 @@ export class EntityDynamicService {
796
785
  const tableName = result.db_table_name;
797
786
 
798
787
  // 2. Get current max sequence number from that table
799
- const seqResult = await this.dataSource.query(
788
+ const seqResult = await this.entityManager.query(
800
789
  `SELECT MAX(id) AS max_seq_no
801
790
  FROM ${tableName}
802
791
  WHERE entity_type = $1`,