rez_core 5.0.89 → 5.0.91

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 (86) hide show
  1. package/dist/module/meta/repository/entity-master.repository.d.ts +3 -1
  2. package/dist/module/meta/repository/entity-master.repository.js +10 -6
  3. package/dist/module/meta/repository/entity-master.repository.js.map +1 -1
  4. package/dist/module/meta/service/entity-relation.service.d.ts +1 -3
  5. package/dist/module/meta/service/entity-relation.service.js +22 -31
  6. package/dist/module/meta/service/entity-relation.service.js.map +1 -1
  7. package/dist/module/module/service/module-access.service.d.ts +3 -1
  8. package/dist/module/module/service/module-access.service.js +11 -4
  9. package/dist/module/module/service/module-access.service.js.map +1 -1
  10. package/dist/module/notification/controller/notification.controller.d.ts +1 -1
  11. package/dist/module/notification/service/notification.service.d.ts +6 -4
  12. package/dist/module/notification/service/notification.service.js +22 -20
  13. package/dist/module/notification/service/notification.service.js.map +1 -1
  14. package/dist/module/workflow/controller/action.controller.d.ts +5 -2
  15. package/dist/module/workflow/controller/form-master.controller.d.ts +4 -1
  16. package/dist/module/workflow/repository/action-data.repository.d.ts +2 -3
  17. package/dist/module/workflow/repository/action-data.repository.js +29 -18
  18. package/dist/module/workflow/repository/action-data.repository.js.map +1 -1
  19. package/dist/module/workflow/repository/action.repository.d.ts +6 -7
  20. package/dist/module/workflow/repository/action.repository.js +53 -61
  21. package/dist/module/workflow/repository/action.repository.js.map +1 -1
  22. package/dist/module/workflow/repository/comm-template.repository.d.ts +2 -3
  23. package/dist/module/workflow/repository/comm-template.repository.js +15 -9
  24. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  25. package/dist/module/workflow/repository/form-master.repository.d.ts +7 -4
  26. package/dist/module/workflow/repository/form-master.repository.js +14 -11
  27. package/dist/module/workflow/repository/form-master.repository.js.map +1 -1
  28. package/dist/module/workflow/repository/stage-group.repository.d.ts +4 -5
  29. package/dist/module/workflow/repository/stage-group.repository.js +34 -35
  30. package/dist/module/workflow/repository/stage-group.repository.js.map +1 -1
  31. package/dist/module/workflow/repository/stage-movement.repository.d.ts +6 -3
  32. package/dist/module/workflow/repository/stage-movement.repository.js +30 -17
  33. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -1
  34. package/dist/module/workflow/service/action.service.d.ts +13 -5
  35. package/dist/module/workflow/service/action.service.js +71 -20
  36. package/dist/module/workflow/service/action.service.js.map +1 -1
  37. package/dist/module/workflow/service/entity-modification.service.d.ts +3 -3
  38. package/dist/module/workflow/service/entity-modification.service.js +4 -4
  39. package/dist/module/workflow/service/entity-modification.service.js.map +1 -1
  40. package/dist/module/workflow/service/form-master.service.d.ts +4 -1
  41. package/dist/module/workflow/service/stage-group.service.d.ts +2 -7
  42. package/dist/module/workflow/service/stage-group.service.js +19 -17
  43. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  44. package/dist/module/workflow/service/stage.service.d.ts +2 -3
  45. package/dist/module/workflow/service/stage.service.js +24 -11
  46. package/dist/module/workflow/service/stage.service.js.map +1 -1
  47. package/dist/module/workflow/service/task.service.d.ts +2 -5
  48. package/dist/module/workflow/service/task.service.js +44 -45
  49. package/dist/module/workflow/service/task.service.js.map +1 -1
  50. package/dist/module/workflow/service/workflow-list-master.service.d.ts +1 -3
  51. package/dist/module/workflow/service/workflow-list-master.service.js +38 -26
  52. package/dist/module/workflow/service/workflow-list-master.service.js.map +1 -1
  53. package/dist/module/workflow/service/workflow-meta.service.d.ts +6 -3
  54. package/dist/module/workflow/service/workflow-meta.service.js +78 -50
  55. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  56. package/dist/module/workflow/service/workflow.service.d.ts +1 -3
  57. package/dist/module/workflow/service/workflow.service.js +10 -6
  58. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  59. package/dist/module/workflow-schedule/processors/schedule.processor.d.ts +4 -2
  60. package/dist/module/workflow-schedule/processors/schedule.processor.js +51 -38
  61. package/dist/module/workflow-schedule/processors/schedule.processor.js.map +1 -1
  62. package/dist/module/workflow-schedule/service/workflow-schedule.service.d.ts +2 -3
  63. package/dist/module/workflow-schedule/service/workflow-schedule.service.js +15 -14
  64. package/dist/module/workflow-schedule/service/workflow-schedule.service.js.map +1 -1
  65. package/dist/tsconfig.build.tsbuildinfo +1 -1
  66. package/package.json +1 -1
  67. package/src/module/meta/repository/entity-master.repository.ts +9 -8
  68. package/src/module/meta/service/entity-relation.service.ts +23 -41
  69. package/src/module/module/service/module-access.service.ts +8 -4
  70. package/src/module/notification/service/notification.service.ts +24 -20
  71. package/src/module/workflow/repository/action-data.repository.ts +33 -28
  72. package/src/module/workflow/repository/action.repository.ts +74 -77
  73. package/src/module/workflow/repository/comm-template.repository.ts +19 -13
  74. package/src/module/workflow/repository/form-master.repository.ts +15 -24
  75. package/src/module/workflow/repository/stage-group.repository.ts +41 -52
  76. package/src/module/workflow/repository/stage-movement.repository.ts +35 -32
  77. package/src/module/workflow/service/action.service.ts +70 -43
  78. package/src/module/workflow/service/entity-modification.service.ts +3 -3
  79. package/src/module/workflow/service/stage-group.service.ts +21 -19
  80. package/src/module/workflow/service/stage.service.ts +36 -28
  81. package/src/module/workflow/service/task.service.ts +53 -56
  82. package/src/module/workflow/service/workflow-list-master.service.ts +42 -34
  83. package/src/module/workflow/service/workflow-meta.service.ts +81 -77
  84. package/src/module/workflow/service/workflow.service.ts +9 -5
  85. package/src/module/workflow-schedule/processors/schedule.processor.ts +133 -97
  86. package/src/module/workflow-schedule/service/workflow-schedule.service.ts +24 -26
@@ -1,6 +1,6 @@
1
1
  import { Injectable, NotFoundException } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
- import { DataSource, Repository } from 'typeorm';
3
+ import { Repository } from 'typeorm';
4
4
  import { CommTemplate } from '../entity/comm-template.entity';
5
5
  import { TemplateAttach } from '../entity/template-attach-mapper.entity';
6
6
  import { MediaDataService } from 'src/module/meta/service/media-data.service';
@@ -14,9 +14,9 @@ export class CommTemplateRepository {
14
14
  @InjectRepository(TemplateAttach)
15
15
  private readonly templateAttachEntity: Repository<TemplateAttach>,
16
16
  private readonly mediaDataService: MediaDataService,
17
- private readonly dataSource: DataSource,
18
17
  private readonly reflectionHelper: ReflectionHelper,
19
- ) {}
18
+ ) {
19
+ }
20
20
 
21
21
  async getAllCommTemplate(
22
22
  entity_type: string,
@@ -35,21 +35,27 @@ export class CommTemplateRepository {
35
35
  where: {
36
36
  id: action_id,
37
37
  organization_id: organization_id,
38
- }
39
- })
38
+ },
39
+ });
40
40
 
41
41
  if (!actionResult) {
42
42
  throw new Error('Invalid action_id');
43
43
  }
44
44
 
45
45
  is_template = actionResult.is_template;
46
- await this.dataSource.query(
47
- `UPDATE frm_wf_comm_template
48
- SET is_template = $1
49
- WHERE mapped_entity_type = $2
50
- AND organization_id = $3 AND level_id = $4 AND level_type=$5`,
51
- [is_template, entity_type, organization_id, level_id, level_type],
52
- );
46
+ await this.commTemplateRepository.find({
47
+ where: {},
48
+ });
49
+
50
+ await this.commTemplateRepository
51
+ .createQueryBuilder()
52
+ .update()
53
+ .set({ is_template: Boolean(is_template) })
54
+ .where('mapped_entity_type = :entityType', { entity_type })
55
+ .andWhere('organization_id = :orgId', { orgId: organization_id })
56
+ .andWhere('level_id = :levelId', { levelId: level_id })
57
+ .andWhere('level_type = :levelType', { levelType: level_type })
58
+ .execute();
53
59
  }
54
60
 
55
61
  const whereCondition: any = {
@@ -145,7 +151,7 @@ export class CommTemplateRepository {
145
151
  async findByCodeAndLevelIdAndLevelTypeAndAppCode(code: string, level_id: string,
146
152
  level_type: string, appcode: string) {
147
153
  return await this.commTemplateRepository.findOne({
148
- where: {code, level_id, level_type, appcode}
154
+ where: { code, level_id, level_type, appcode },
149
155
  });
150
156
  }
151
157
  }
@@ -1,36 +1,27 @@
1
- import {
2
- BadRequestException,
3
- Inject,
4
- Injectable,
5
- NotFoundException,
6
- } from '@nestjs/common';
7
- import { InjectRepository } from '@nestjs/typeorm';
8
- import { DataSource, Repository } from 'typeorm';
9
- import { FormDataEntity } from '../entity/form.entity';
1
+ import { Injectable } from '@nestjs/common';
10
2
  import { UserData } from 'src/module/user/entity/user.entity';
3
+ import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
11
4
 
12
5
  @Injectable()
13
6
  export class FormMasterRepository {
14
7
  constructor(
15
- private readonly dataSource: DataSource,
16
- // @InjectRepository(FormDataEntity)
17
- // private readonly formRepo: Repository<FormDataEntity>,
8
+ private readonly reflectionHelper: ReflectionHelper,
18
9
  ) {}
19
10
 
20
11
  async getForms(organization_id: number, source_entity_type: string) {
21
- const forms = await this.dataSource.query(
22
- `SELECT fm.id as fm_id, fm.name as fm_form_name
23
- FROM frm_entity_view fm
24
- WHERE fm.organization_id = $1 AND fm.mapped_entity_type = $2`,
25
- [organization_id, source_entity_type],
26
- );
27
-
28
- const formatted = forms.map((form: any) => ({
29
- label: form.fm_form_name,
30
- value: form.fm_id,
31
- }));
32
12
 
33
- return formatted;
13
+ const viewMasterRepo = this.reflectionHelper.getRepoService('ViewMaster');
14
+ const forms = await viewMasterRepo.find({
15
+ where: {
16
+ organization_id,
17
+ mapped_entity_type: source_entity_type
18
+ }
19
+ });
20
+
21
+ return forms.map((form: any) => ({
22
+ label: form.name,
23
+ value: form.id,
24
+ }));
34
25
  }
35
26
 
36
27
  // to_be_sent
@@ -1,15 +1,10 @@
1
- import {
2
- BadRequestException,
3
- Inject,
4
- Injectable,
5
- NotFoundException,
6
- } from '@nestjs/common';
1
+ import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
7
2
  import { StageGroup } from '../entity/stage-group.entity';
8
3
  import { InjectRepository } from '@nestjs/typeorm';
9
- import { DataSource, In, Repository } from 'typeorm';
10
- import { MediaDataService } from 'src/module/meta/service/media-data.service';
4
+ import { In, Repository } from 'typeorm';
11
5
  import { Stage } from '../entity/stage.entity';
12
6
  import { TaskDataEntity } from '../entity/task-data.entity';
7
+ import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
13
8
 
14
9
  @Injectable()
15
10
  export class StageGroupRepository {
@@ -20,9 +15,9 @@ export class StageGroupRepository {
20
15
  private readonly stageRepository: Repository<Stage>,
21
16
  @InjectRepository(TaskDataEntity)
22
17
  private readonly taskDataRepo: Repository<TaskDataEntity>,
23
- private readonly dataSource: DataSource,
24
- private readonly mediaDataService: MediaDataService,
25
- ) {}
18
+ private readonly reflectionHelper: ReflectionHelper,
19
+ ) {
20
+ }
26
21
 
27
22
  async getAllStageGroup(workflow_id: number, organization_id: number) {
28
23
  if (!workflow_id) {
@@ -93,12 +88,12 @@ export class StageGroupRepository {
93
88
  const stagesRaw: any[] = await this.stageRepository.find({
94
89
  where: {
95
90
  stage_group_id: In(stageGroupIds),
96
- organization_id: loggedInUser.organization_id
91
+ organization_id: loggedInUser.organization_id,
97
92
  },
98
93
  order: {
99
94
  sequence: 'ASC',
100
- }
101
- })
95
+ },
96
+ });
102
97
 
103
98
  const stageIds = stagesRaw.map((s) => Number(s.id));
104
99
 
@@ -109,52 +104,46 @@ export class StageGroupRepository {
109
104
  // -------------------------------------------------------------
110
105
  // STEP 3: Task Counts (Postgres-safe)
111
106
  // -------------------------------------------------------------
112
- const stagePlaceholders = stageIds
113
- .map((_, idx) => `$${idx + 1}`)
114
- .join(", ");
115
-
116
- const params_task = [...stageIds];
117
-
118
- const taskCounts = await this.dataSource.query(
119
- `
120
- SELECT stage_id, COUNT(*) AS task_count
121
- FROM frm_wf_task_data
122
- WHERE stage_id IN (${stagePlaceholders})
123
- AND is_system = FALSE
124
- AND mapped_entity_id = ${lead_id}
125
- GROUP BY stage_id
126
- `,
127
- params_task,
128
- );
107
+
108
+ const taskCounts = await this.taskDataRepo
109
+ .createQueryBuilder('t')
110
+ .select('t.stage_id', 'stage_id')
111
+ .addSelect('COUNT(*)', 'task_count')
112
+ .where('t.stage_id IN (:...stageIds)', { stageIds })
113
+ .andWhere('t.is_system = false')
114
+ .andWhere('t.mapped_entity_id = :leadId', { leadId: lead_id })
115
+ .groupBy('t.stage_id')
116
+ .getRawMany();
129
117
 
130
118
  // -------------------------------------------------------------
131
119
  // STEP 4: Meeting Counts
132
120
  // -------------------------------------------------------------
133
- const meetingCounts = await this.dataSource.query(
134
- `
135
- SELECT stage_id, COUNT(*) AS meeting_count
136
- FROM crm_lead_meeting
137
- WHERE stage_id IN (${stagePlaceholders})
138
- AND mapped_entity_id = ${lead_id}
139
- GROUP BY stage_id
140
- `,
141
- params_task,
142
- );
121
+
122
+ const leadMeetingRepo = this.reflectionHelper.getRepoService('LeadScheduleMeet');
123
+
124
+ const meetingCounts = await leadMeetingRepo
125
+ .createQueryBuilder('m')
126
+ .select('m.stage_id', 'stage_id')
127
+ .addSelect('COUNT(*)', 'meeting_count')
128
+ .where('m.stage_id IN (:...stageIds)', { stageIds })
129
+ .andWhere('m.mapped_entity_id = :leadId', { leadId: lead_id })
130
+ .groupBy('m.stage_id')
131
+ .getRawMany();
143
132
 
144
133
  // -------------------------------------------------------------
145
134
  // STEP 5: Send Communication Counts
146
135
  // -------------------------------------------------------------
147
- const sendCommCounts = await this.dataSource.query(
148
- `
149
- SELECT stage_id, COUNT(*) AS send_comm_count
150
- FROM crm_lead_communication
151
- WHERE stage_id IN (${stagePlaceholders})
152
- AND mapped_entity_id = ${lead_id}
153
- AND type IN ('SEND','LOG')
154
- GROUP BY stage_id
155
- `,
156
- params_task,
157
- );
136
+ const leadCommunicationRepo = this.reflectionHelper.getRepoService('LeadCommunication');
137
+
138
+ const sendCommCounts = await leadCommunicationRepo
139
+ .createQueryBuilder('c')
140
+ .select('c.stage_id', 'stage_id')
141
+ .addSelect('COUNT(*)', 'send_comm_count')
142
+ .where('c.stage_id IN (:...stageIds)', { stageIds })
143
+ .andWhere('c.mapped_entity_id = :leadId', { leadId: lead_id })
144
+ .andWhere('c.type IN (:...types)', { types: ['SEND', 'LOG'] })
145
+ .groupBy('c.stage_id')
146
+ .getRawMany();
158
147
 
159
148
  // Convert to maps
160
149
  const taskCountMap = new Map(
@@ -1,13 +1,13 @@
1
- import { get } from 'http';
2
1
  import { Injectable } from '@nestjs/common';
3
2
  import { InjectRepository } from '@nestjs/typeorm';
4
- import { Repository, DataSource, MoreThan } from 'typeorm';
3
+ import { MoreThan, Repository } from 'typeorm';
5
4
  import { WorkflowLevelMappingEntity } from '../entity/workflow-level-mapping.entity';
6
5
  import { StageGroup } from '../entity/stage-group.entity';
7
6
  import { Stage } from '../entity/stage.entity';
8
- import { log } from 'console';
9
7
  import { UserData } from 'src/module/user/entity/user.entity';
10
8
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
9
+ import { ActionDataEntity } from '../entity/action-data.entity';
10
+ import { TaskDataEntity } from '../entity/task-data.entity';
11
11
 
12
12
  @Injectable()
13
13
  export class StageMovementRepository {
@@ -18,8 +18,11 @@ export class StageMovementRepository {
18
18
  private readonly stageGroupRepo: Repository<StageGroup>,
19
19
  @InjectRepository(Stage)
20
20
  private readonly stageRepo: Repository<Stage>,
21
- private readonly dataSource: DataSource,
22
21
  private readonly reflectionHelper: ReflectionHelper,
22
+ @InjectRepository(ActionDataEntity)
23
+ private readonly actionDataEntityRepository: Repository<ActionDataEntity>,
24
+ @InjectRepository(TaskDataEntity)
25
+ private readonly taskDataEntityRepository: Repository<TaskDataEntity>,
23
26
  ) {}
24
27
 
25
28
  async getFirstStage({
@@ -183,40 +186,40 @@ export class StageMovementRepository {
183
186
  }
184
187
 
185
188
  async getAllActionByStageId(stageId: number): Promise<any> {
186
-
187
189
  const actionRepo = this.reflectionHelper.getRepoService('ActionEntity');
188
190
  const result = await actionRepo
189
- .createQueryBuilder("a")
191
+ .createQueryBuilder('a')
190
192
  .leftJoin(
191
- "frm_wf_stage_action_mapping",
192
- "m",
193
- "a.id = m.action_id::bigint"
193
+ 'frm_wf_stage_action_mapping',
194
+ 'm',
195
+ 'a.id = m.action_id::bigint',
194
196
  )
195
197
  .leftJoin(
196
- "frm_wf_action_category",
197
- "ac",
198
- "a.action_category::bigint = ac.id"
198
+ 'frm_wf_action_category',
199
+ 'ac',
200
+ 'a.action_category::bigint = ac.id',
199
201
  )
200
- .where("m.stage_id::bigint = :stageId", { stageId: Number(stageId) })
202
+ .where('m.stage_id::bigint = :stageId', { stageId: Number(stageId) })
201
203
  .select([
202
- "a.*", // select all columns from action table
203
- "m.id AS mapping_id",
204
- "m.stage_id",
205
- "ac.code AS action_category_code",
204
+ 'a.*', // select all columns from action table
205
+ 'm.id AS mapping_id',
206
+ 'm.stage_id AS stage_id',
207
+ 'ac.code AS action_category_code',
206
208
  ])
207
- .orderBy("a.sequence", "ASC")
209
+ .orderBy('a.sequence', 'ASC')
208
210
  .getRawMany();
209
211
 
210
212
  // Use for..of with await instead of map
211
- const actionResourceMappingRepo = this.reflectionHelper.getRepoService('ActionResourcesMapping');
213
+ const actionResourceMappingRepo = this.reflectionHelper.getRepoService(
214
+ 'ActionResourcesMapping',
215
+ );
212
216
  for (const item of result) {
213
217
  if (item.action_category_code === 'SDFM') {
214
218
  const actionData = await actionResourceMappingRepo.findOne({
215
219
  where: {
216
- stg_act_mapping_id: item.mapping_id
217
- }
218
- })
219
-
220
+ stg_act_mapping_id: item.mapping_id,
221
+ },
222
+ });
220
223
 
221
224
  item.form_id = actionData?.form_id || null;
222
225
  }
@@ -230,23 +233,23 @@ export class StageMovementRepository {
230
233
 
231
234
  if (action.length > 0) {
232
235
  for (const act of action) {
233
- await this.dataSource.query(
234
- `INSERT INTO frm_wf_action_data (stage_id, user_id, action_id) VALUES ($1, $2, $3)`,
235
- [act.stage_id, loggedInUser.id, act.id],
236
- );
236
+ await this.actionDataEntityRepository.save({
237
+ stage_id: act.stage_id,
238
+ user_id: loggedInUser.id,
239
+ action_id: act.id,
240
+ });
237
241
  }
238
242
  }
239
243
  }
240
244
 
241
245
  async saveTaskData(actionData: any, loggedInUser: UserData): Promise<any> {
242
246
  // Implement the logic to save task data
243
-
244
247
  if (actionData.length > 0) {
245
248
  for (const action of actionData) {
246
- await this.dataSource.query(
247
- `INSERT INTO frm_wf_task_data (action_id, user_id) VALUES ($1, $2)`,
248
- [action.id, loggedInUser.id],
249
- );
249
+ await this.taskDataEntityRepository.save({
250
+ action_id: action.id,
251
+ user_id: String(loggedInUser.id),
252
+ });
250
253
  }
251
254
  }
252
255
  }
@@ -1,16 +1,25 @@
1
- import { BadRequestException, Injectable } from '@nestjs/common';
1
+ import { Injectable } from '@nestjs/common';
2
2
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
4
4
  import { UserData } from 'src/module/user/entity/user.entity';
5
- import { DataSource, EntityManager, Repository } from 'typeorm';
5
+ import { EntityManager, Repository } from 'typeorm';
6
6
  import { ActionRepository } from '../repository/action.repository';
7
7
  import { ActionEntity } from '../entity/action.entity';
8
+ import { ActionResourcesMapping } from '../entity/action-resources-mapping.entity';
9
+ import { InjectRepository } from '@nestjs/typeorm';
10
+ import { StageActionMapping } from '../entity/stage-action-mapping.entity';
11
+ import { ActionTemplateMapping } from '../entity/action-template-mapping.entity';
8
12
 
9
13
  @Injectable()
10
14
  export class ActionService extends EntityServiceImpl {
11
15
  constructor(
12
- private readonly dataSource: DataSource,
13
16
  private readonly actionRepository: ActionRepository,
17
+ @InjectRepository(ActionResourcesMapping)
18
+ private readonly actionResourcesMappingRepository: Repository<ActionResourcesMapping>,
19
+ @InjectRepository(StageActionMapping)
20
+ private readonly stageActionMappingRepository: Repository<StageActionMapping>,
21
+ @InjectRepository(ActionTemplateMapping)
22
+ private readonly actionTemplateMappingRepository: Repository<ActionTemplateMapping>,
14
23
  ) {
15
24
  super();
16
25
  }
@@ -26,16 +35,25 @@ export class ActionService extends EntityServiceImpl {
26
35
  return null;
27
36
  }
28
37
 
29
- const result = await this.dataSource.query(
30
- `SELECT template_code, form_id
31
- FROM frm_wf_action_resources_mapping
32
- WHERE stg_act_mapping_id IN (
33
- SELECT id
34
- FROM frm_wf_stage_action_mapping
35
- WHERE action_id = $1 AND entity_type = 'WFSA'
36
- )`,
37
- [actionData.id],
38
- );
38
+ let actionResourceMappingRepo = this.reflectionHelper.getRepoService('ActionResourcesMapping');
39
+ await actionResourceMappingRepo.find({
40
+ where: {},
41
+ });
42
+
43
+ const result = await actionResourceMappingRepo
44
+ .createQueryBuilder('arm')
45
+ .select([
46
+ 'arm.template_code AS template_code',
47
+ 'arm.form_id AS form_id',
48
+ ])
49
+ .where(`arm.stg_act_mapping_id IN (
50
+ SELECT sam.id
51
+ FROM frm_wf_stage_action_mapping sam
52
+ WHERE sam.action_id = :actionId
53
+ AND sam.entity_type = 'WFSA'
54
+ )`)
55
+ .setParameter('actionId', actionData.id)
56
+ .getRawMany();
39
57
 
40
58
  const templates = result
41
59
  .filter((t) => t.template_code !== null)
@@ -59,10 +77,10 @@ export class ActionService extends EntityServiceImpl {
59
77
  const actionData = entityData as any;
60
78
 
61
79
  // 🔧 Remove 'template' array before inserting main action
62
- const { template, ...actionWithoutTemplates } = actionData;
80
+ const { template, ...actionWithoutTemplates } = actionData;
63
81
 
64
- // Step 1: Create main action entity
65
- const action = await super.createEntity(actionWithoutTemplates, loggedInUser);
82
+ // Step 1: Create main action entity
83
+ const action = await super.createEntity(actionWithoutTemplates, loggedInUser);
66
84
 
67
85
  // Step 2: Create stage mapping
68
86
  const stageActionMapping = {
@@ -100,10 +118,10 @@ export class ActionService extends EntityServiceImpl {
100
118
  }
101
119
  }
102
120
 
103
- await this.dataSource.query(
104
- `DELETE FROM frm_wf_action_resources_mapping WHERE stg_act_mapping_id = $1 AND type = 'form'`,
105
- [stageActionMappingData.id],
106
- );
121
+ await this.actionResourcesMappingRepository.delete({
122
+ stg_act_mapping_id: stageActionMappingData.id,
123
+ type: 'form',
124
+ });
107
125
 
108
126
  if (actionData.form) {
109
127
  const resourceMapping = {
@@ -140,17 +158,19 @@ export class ActionService extends EntityServiceImpl {
140
158
  throw new Error('Action not found or could not be updated');
141
159
  }
142
160
 
143
- const stageMapID = await this.dataSource.query(
144
- `SELECT id FROM frm_wf_stage_action_mapping WHERE action_id = $1 AND entity_type = 'WFSA'`,
145
- [action.id],
146
- );
161
+ const stageMap = await this.stageActionMappingRepository.findOne({
162
+ where: {
163
+ action_id: action.id,
164
+ entity_type: 'WFSA',
165
+ },
166
+ });
147
167
 
148
168
  let stageActionMappingData;
149
169
 
150
- if (stageMapID.length > 0) {
170
+ if (stageMap) {
151
171
  // Update existing mapping
152
172
  const stageActionMapping = {
153
- id: stageMapID[0].id,
173
+ id: stageMap.id,
154
174
  action_id: action.id,
155
175
  stage_id,
156
176
  entity_type: 'WFSA',
@@ -176,10 +196,10 @@ export class ActionService extends EntityServiceImpl {
176
196
  }
177
197
 
178
198
  // delete existing template mappings for this action
179
- await this.dataSource.query(
180
- `DELETE FROM frm_wf_action_resources_mapping WHERE stg_act_mapping_id = $1 AND type = 'template'`,
181
- [stageActionMappingData.id],
182
- );
199
+ await this.actionResourcesMappingRepository.delete({
200
+ stg_act_mapping_id: stageActionMappingData.id,
201
+ type: 'template',
202
+ });
183
203
 
184
204
  // Handle template mapping (using the extracted template)
185
205
  if (Array.isArray(template) && template.length > 0) {
@@ -199,10 +219,10 @@ export class ActionService extends EntityServiceImpl {
199
219
  }
200
220
  }
201
221
 
202
- await this.dataSource.query(
203
- `DELETE FROM frm_wf_action_resources_mapping WHERE stg_act_mapping_id = $1 AND type = 'form'`,
204
- [stageActionMappingData.id],
205
- );
222
+ await this.actionResourcesMappingRepository.delete({
223
+ stg_act_mapping_id: stageActionMappingData.id,
224
+ type: 'form',
225
+ });
206
226
 
207
227
  if (form) {
208
228
  const resourceMapping = {
@@ -222,16 +242,23 @@ export class ActionService extends EntityServiceImpl {
222
242
  id: number,
223
243
  loggedInUser: UserData,
224
244
  ): Promise<any> {
225
- await this.dataSource.query(
226
- `DELETE FROM frm_wf_action_template_mapping WHERE stg_act_mapping_id IN (SELECT
227
- id FROM frm_wf_stage_action_mapping WHERE action_id = $1 AND entity_type = 'WFSA')`,
228
- [id],
229
- );
230
245
 
231
- await this.dataSource.query(
232
- `DELETE FROM frm_wf_stage_action_mapping WHERE action_id = $1 AND entity_type ='WFSA'`,
233
- [id],
234
- );
246
+ await this.actionTemplateMappingRepository
247
+ .createQueryBuilder()
248
+ .delete()
249
+ .where(`stg_act_mapping_id IN (
250
+ SELECT sam.id
251
+ FROM frm_wf_stage_action_mapping sam
252
+ WHERE sam.action_id = :actionId
253
+ AND sam.entity_type = 'WFSA'
254
+ )`)
255
+ .setParameter('actionId', id)
256
+ .execute();
257
+
258
+ await this.stageActionMappingRepository.delete({
259
+ action_id: id,
260
+ entity_type: 'WFSA',
261
+ });
235
262
 
236
263
  const deleteAction = await super.deleteEntity(entityType, id, loggedInUser);
237
264
 
@@ -5,12 +5,12 @@ import {
5
5
  } from '@nestjs/common';
6
6
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
7
7
  import { UserData } from 'src/module/user/entity/user.entity';
8
- import { DataSource } from 'typeorm';
8
+ import { DataSource, EntityManager } from 'typeorm';
9
9
  import { EntityMasterService } from '../../meta/service/entity-master.service';
10
10
 
11
11
  @Injectable()
12
12
  export class EntityModificationService extends EntityServiceImpl {
13
- constructor(private readonly dataSource: DataSource
13
+ constructor(private readonly entityManager: EntityManager
14
14
  ) {
15
15
  super();
16
16
  }
@@ -36,7 +36,7 @@ export class EntityModificationService extends EntityServiceImpl {
36
36
  const tableName = entityMeta.db_table_name;
37
37
 
38
38
  // Step 2: Get the row from the target table using mapped_entity_id
39
- const [entityRow] = await this.dataSource.query(
39
+ const [entityRow] = await this.entityManager.query(
40
40
  `
41
41
  SELECT * FROM ${tableName} WHERE id = $1
42
42
  `,
@@ -1,21 +1,17 @@
1
- import { app } from 'firebase-admin';
2
1
  import { BadGatewayException, Inject, Injectable } from '@nestjs/common';
3
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
4
3
  import { StageGroupRepository } from '../repository/stage-group.repository';
5
4
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
6
5
  import { UserData } from 'src/module/user/entity/user.entity';
7
6
  import { StageService } from './stage.service';
8
- import { DataSource, Repository } from 'typeorm';
9
- import { WorkflowLevelMappingEntity } from '../entity/workflow-level-mapping.entity';
7
+ import { Repository } from 'typeorm';
10
8
  import { InjectRepository } from '@nestjs/typeorm';
11
9
  import { StageMovementData } from '../entity/stage-movement-data.entity';
12
10
  import * as moment from 'moment';
13
- import { MediaDataService } from 'src/module/meta/service/media-data.service';
14
11
  import axios from 'axios';
15
12
  import { ConfigService } from '@nestjs/config';
16
13
  import { ListMasterData } from 'src/module/listmaster/entity/list-master.entity';
17
14
  import { StageGroup } from '../entity/stage-group.entity';
18
- import { EntityMasterService } from 'src/module/meta/service/entity-master.service';
19
15
 
20
16
  @Injectable()
21
17
  export class StageGroupService extends EntityServiceImpl {
@@ -23,12 +19,8 @@ export class StageGroupService extends EntityServiceImpl {
23
19
  private readonly stageGroupRepository: StageGroupRepository,
24
20
  @Inject('StageService')
25
21
  private readonly stageService: StageService,
26
- private readonly dataSource: DataSource,
27
- @InjectRepository(WorkflowLevelMappingEntity)
28
- private readonly workflowLevelMappingRepo: Repository<WorkflowLevelMappingEntity>,
29
22
  @InjectRepository(StageMovementData)
30
23
  private readonly stageMovementRepo: Repository<StageMovementData>,
31
- private readonly mediaDataService: MediaDataService,
32
24
  private readonly configService: ConfigService,
33
25
  @InjectRepository(ListMasterData)
34
26
  private readonly listMasterRepo: Repository<ListMasterData>,
@@ -37,17 +29,21 @@ export class StageGroupService extends EntityServiceImpl {
37
29
  ) {
38
30
  super();
39
31
  }
32
+
40
33
  async getAllStageGroup(workflow_id: number, organization_id: number) {
41
34
  const allStageGroup = await this.stageGroupRepository.getAllStageGroup(
42
35
  workflow_id,
43
36
  organization_id,
44
37
  );
45
- const statusListMaster = await this.dataSource.query(
46
- `SELECT id, name
47
- FROM frm_list_master_items
48
- WHERE listtype = 'STS' AND organization_id = $1`,
49
- [organization_id],
50
- );
38
+
39
+ const listMasterItemsRepo = this.reflectionHelper.getRepoService('ListMasterItems');
40
+
41
+ const statusListMaster = await listMasterItemsRepo.find({
42
+ where: {
43
+ listtype: 'STS',
44
+ organization_id,
45
+ },
46
+ });
51
47
 
52
48
  // Build a lookup map: id → name
53
49
  const statusMap = new Map(
@@ -320,10 +316,16 @@ export class StageGroupService extends EntityServiceImpl {
320
316
  id: number,
321
317
  loggedInUser: UserData,
322
318
  ): Promise<any> {
323
- const getAllStage = await this.dataSource.query(
324
- `SELECT id FROM frm_wf_stage WHERE stage_group_id = $1 AND level_id = $2 AND level_type = $3`,
325
- [id, loggedInUser.level_id, loggedInUser.level_type],
326
- );
319
+
320
+ const stageRepo = this.reflectionHelper.getRepoService('Stage');
321
+
322
+ const getAllStage = await stageRepo.find({
323
+ where: {
324
+ stage_group_id: id,
325
+ level_id: loggedInUser.level_id,
326
+ level_type: loggedInUser.level_type,
327
+ },
328
+ });
327
329
 
328
330
  if (getAllStage.length > 0) {
329
331
  for (const stage of getAllStage) {