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
@@ -24,7 +24,6 @@ export class StageService extends EntityServiceImpl {
24
24
  private readonly stageGroupRepository: StageGroupRepository,
25
25
  @InjectRepository(StageMovementData)
26
26
  private readonly stageMovementRepo: Repository<StageMovementData>,
27
- private readonly dataSource: DataSource,
28
27
  @Inject('ActionService')
29
28
  private readonly actionService: ActionService,
30
29
  ) {
@@ -39,24 +38,33 @@ export class StageService extends EntityServiceImpl {
39
38
  organization_id: number,
40
39
  show_previous: boolean,
41
40
  ) {
41
+ const listRepo = this.reflectionHelper.getRepoService('ListMasterItems');
42
+ const stageMovementRepo =
43
+ this.reflectionHelper.getRepoService('StageMovementData');
44
+
42
45
  if (!show_previous) {
43
46
  const allStages = await this.stageRepository.getAllStage(
44
47
  payload.stage_group_id,
45
48
  organization_id,
46
49
  );
47
50
 
48
- const statusListMaster = await this.dataSource.query(
49
- `SELECT id, name
50
- FROM frm_list_master_items
51
- WHERE listtype = 'STS' AND organization_id = $1`,
52
- [organization_id],
53
- );
54
-
55
- // Build a lookup map: id → name
51
+ const statusListMaster = await listRepo.find({
52
+ where: {
53
+ listtype: 'STS',
54
+ organization_id: organization_id,
55
+ },
56
+ select: {
57
+ id: true,
58
+ name: true,
59
+ },
60
+ });
61
+
62
+ // id → name map
56
63
  const statusMap = new Map(
57
64
  statusListMaster.map((s) => [String(s.id), s.name]),
58
65
  );
59
66
 
67
+ // Replace status IDs with names
60
68
  for (const stage of allStages) {
61
69
  stage.status = statusMap.get(String(stage.status)) as any;
62
70
  }
@@ -64,22 +72,15 @@ export class StageService extends EntityServiceImpl {
64
72
  return allStages;
65
73
  }
66
74
 
67
- // 1. Get all stages up to the current stage group
75
+ // 1. Get all stage groups & stages
68
76
  const allStageWithStageGroup =
69
77
  await this.stageRepository.getAllStageGroupAndStageByStageMovement(
70
78
  payload.stage_group_id,
71
79
  organization_id,
72
80
  );
73
81
 
74
- // 2. Get stage movement history for this entity
75
- const allStageMovementData = await this.dataSource.manager.find<{
76
- id: number;
77
- stage_group_id: number;
78
- stage_id: number;
79
- mapped_entity_id: number;
80
- mapped_entity_type: string;
81
- is_current: string;
82
- }>('frm_wf_stage_movement_data', {
82
+ // 2. Replace raw manager.find with proper repository
83
+ const allStageMovementData = await stageMovementRepo.find({
83
84
  where: {
84
85
  mapped_entity_id: payload.mapped_entity_id,
85
86
  mapped_entity_type: 'LEAD',
@@ -91,7 +92,7 @@ export class StageService extends EntityServiceImpl {
91
92
  return allStageWithStageGroup;
92
93
  }
93
94
 
94
- // 3. Find the current stage movement (is_current === 'Y')
95
+ // 3. Find the current stage movement
95
96
  const currentMovement = allStageMovementData.find(
96
97
  (m) => m.is_current === 'Y',
97
98
  );
@@ -100,13 +101,11 @@ export class StageService extends EntityServiceImpl {
100
101
  return allStageWithStageGroup;
101
102
  }
102
103
 
103
- // 4. Filter stages up to and including the current stage_id
104
+ // 4. Filter stages up to current stage_id
104
105
  const filteredStages: any[] = [];
105
106
  for (const stage of allStageWithStageGroup) {
106
107
  filteredStages.push(stage);
107
- if (stage.id === currentMovement.stage_id) {
108
- break; // stop once we reach the current stage
109
- }
108
+ if (stage.id === currentMovement.stage_id) break;
110
109
  }
111
110
 
112
111
  return filteredStages;
@@ -132,11 +131,19 @@ export class StageService extends EntityServiceImpl {
132
131
  id: number,
133
132
  loggedInUser: UserData,
134
133
  ): Promise<any> {
135
- const getAllStageAction = await this.dataSource.query(
136
- `SELECT action_id FROM frm_wf_stage_action_mapping WHERE stage_id = $1 AND entity_type = 'WFSA'`,
137
- [id],
138
- );
134
+ const stageActionRepo =
135
+ this.reflectionHelper.getRepoService('StageActionMapping');
136
+
137
+ // 1. Fetch all actions mapped to this stage (replaces raw SQL)
138
+ const getAllStageAction = await stageActionRepo.find({
139
+ where: {
140
+ stage_id: id,
141
+ entity_type: 'WFSA',
142
+ },
143
+ select: ['action_id'],
144
+ });
139
145
 
146
+ // 2. Delete all related WFSA actions
140
147
  if (getAllStageAction.length > 0) {
141
148
  for (const action of getAllStageAction) {
142
149
  await this.actionService.deleteEntity(
@@ -147,6 +154,7 @@ export class StageService extends EntityServiceImpl {
147
154
  }
148
155
  }
149
156
 
157
+ // 3. Delete the stage itself
150
158
  const deleteStage = await super.deleteEntity(entityType, id, loggedInUser);
151
159
 
152
160
  return deleteStage;
@@ -6,13 +6,10 @@ import { ActionDataService } from './action-data.service';
6
6
  import { DataSource, EntityManager } from 'typeorm';
7
7
  import { ActivityLogService } from './activity-log.service';
8
8
  import { ACTIVITY_CATEGORIES } from '../repository/activity-log.repository';
9
- import { MediaDataService } from 'src/module/meta/service/media-data.service';
10
9
  import { ActionHandler } from 'src/module/workflow-automation/interface/action.decorator';
11
10
  import * as moment from 'moment';
12
11
  import { ConfigService } from '@nestjs/config';
13
12
  import axios from 'axios';
14
- import { ChecksumAlgorithm } from '@aws-sdk/client-s3';
15
- import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
16
13
 
17
14
  @Injectable()
18
15
  @ActionHandler('add_task')
@@ -20,10 +17,8 @@ export class TaskService extends EntityServiceImpl {
20
17
  constructor(
21
18
  private readonly taskRepository: TaskRepository,
22
19
  private readonly actionDataService: ActionDataService,
23
- private readonly dataSource: DataSource,
24
20
  @Inject('ActivityLogService')
25
21
  private readonly activityLogService: ActivityLogService,
26
- private readonly mediaDataService: MediaDataService,
27
22
  private readonly configService: ConfigService,
28
23
  ) {
29
24
  super();
@@ -108,23 +103,25 @@ export class TaskService extends EntityServiceImpl {
108
103
  // Logging should not block main flow
109
104
  }
110
105
 
111
- let relationData = await this.dataSource.query(
112
- `SELECT * FROM frm_entity_relation WHERE source_entity_type = $1 AND target_entity_type = $2`,
113
- [createdEntity.mapped_entity_type, createdEntity.entity_type],
114
- );
106
+ const entityRelationRepo =
107
+ this.reflectionHelper.getRepoService('EntityRelationData');
108
+
109
+ let relationData = await entityRelationRepo.findOne({
110
+ where: {
111
+ source_entity_type: createdEntity.mapped_entity_type,
112
+ target_entity_type: createdEntity.entity_type,
113
+ },
114
+ });
115
115
 
116
116
  if (relationData) {
117
- await this.dataSource.query(
118
- `INSERT INTO frm_entity_relation_data (organization_id, source_entity_id, source_entity_type, target_entity_id, target_entity_type, relation_type) VALUES ($1, $2, $3, $4, $5 , $6)`,
119
- [
120
- loggedInUser.organization_id,
121
- createdEntity.mapped_entity_id,
122
- createdEntity.mapped_entity_type,
123
- createdEntity.id,
124
- createdEntity.entity_type,
125
- relationData[0]?.relation_type,
126
- ],
127
- );
117
+ await entityRelationRepo.save({
118
+ organization_id: loggedInUser.organization_id,
119
+ source_entity_id: createdEntity.mapped_entity_id,
120
+ source_entity_type: createdEntity.mapped_entity_type,
121
+ target_entity_id: createdEntity.id,
122
+ target_entity_type: createdEntity.entity_type,
123
+ relation_type: relationData?.relation_type,
124
+ });
128
125
  }
129
126
 
130
127
  return createdEntity;
@@ -135,37 +132,35 @@ export class TaskService extends EntityServiceImpl {
135
132
  loggedInUser: UserData,
136
133
  appcode?: string,
137
134
  ): Promise<any> {
138
- const taskStatusQuery = `
139
- SELECT name
140
- FROM frm_list_master_items
141
- WHERE id = $1
142
- AND organization_id = $2
143
- AND listtype = 'TKST'
144
- LIMIT 1;
145
- `;
146
-
147
- const statusRows = await this.dataSource.query(taskStatusQuery, [
148
- entityData.status,
149
- loggedInUser.organization_id,
150
- ]);
151
-
152
- const oldStatusQuery = `
153
- SELECT *
154
- FROM frm_wf_task_data
155
- WHERE id = $1
156
- AND organization_id = $2
157
- LIMIT 1;
158
- `;
159
-
160
- const [oldRow] = await this.dataSource.query(oldStatusQuery, [
161
- entityData.id,
162
- loggedInUser.organization_id,
163
- ]);
164
-
165
- const oldStatusRows = await this.dataSource.query(taskStatusQuery, [
166
- oldRow.status,
167
- loggedInUser.organization_id,
168
- ]);
135
+ const listRepo = this.reflectionHelper.getRepoService('ListMasterItems');
136
+ const taskRepo = this.reflectionHelper.getRepoService('TaskDataEntity');
137
+
138
+ const statusRows = await listRepo.find({
139
+ where: {
140
+ id: entityData.status,
141
+ organization_id: loggedInUser.organization_id,
142
+ listtype: 'TKST',
143
+ },
144
+ take: 1,
145
+ });
146
+
147
+ const oldRow = await taskRepo.findOne({
148
+ where: {
149
+ id: entityData.id,
150
+ organization_id: loggedInUser.organization_id,
151
+ },
152
+ });
153
+
154
+ const oldStatusRows = oldRow
155
+ ? await listRepo.find({
156
+ where: {
157
+ id: oldRow.status,
158
+ organization_id: loggedInUser.organization_id,
159
+ listtype: 'TKST',
160
+ },
161
+ take: 1,
162
+ })
163
+ : [];
169
164
 
170
165
  const isStatusChanged =
171
166
  statusRows.length > 0 &&
@@ -176,7 +171,6 @@ export class TaskService extends EntityServiceImpl {
176
171
  statusRows.length > 0 &&
177
172
  statusRows[0].name?.toLowerCase() === 'completed';
178
173
 
179
- // Sync flags based on status
180
174
  entityData.is_completed = isCompletedStatus;
181
175
  entityData.is_done = isCompletedStatus;
182
176
 
@@ -195,11 +189,14 @@ export class TaskService extends EntityServiceImpl {
195
189
  appcode,
196
190
  );
197
191
 
198
- // Convert boolean back to "1" / "0" for response
192
+ // Convert boolean "1"/"0"
199
193
  if (updatedEntity && typeof updatedEntity['is_mandatory'] === 'boolean') {
200
194
  updatedEntity['is_mandatory'] = updatedEntity['is_mandatory'] ? '1' : '0';
201
195
  }
202
196
 
197
+ // -------------------------------
198
+ // Logging Activity
199
+ // -------------------------------
203
200
  try {
204
201
  if (isCompletedStatus && isStatusChanged) {
205
202
  const completedLogData = {
@@ -234,7 +231,6 @@ export class TaskService extends EntityServiceImpl {
234
231
  'Failed to log activity for task:',
235
232
  error?.message || error,
236
233
  );
237
- // Don't block main flow
238
234
  }
239
235
 
240
236
  return updatedEntity;
@@ -524,12 +520,13 @@ export class TaskService extends EntityServiceImpl {
524
520
  loggedInUser: any,
525
521
  ) {
526
522
  if (!entity || !entity.mapped_entity_id || !entity.reason_code) return null;
527
- const listMasterItemRepo = this.reflectionHelper.getRepoService('ListMasterItems');
523
+ const listMasterItemRepo =
524
+ this.reflectionHelper.getRepoService('ListMasterItems');
528
525
  const reason = await listMasterItemRepo.findOne({
529
526
  where: {
530
527
  id: entity.reason_code,
531
528
  organization_id: loggedInUser.organization_id,
532
- }
529
+ },
533
530
  });
534
531
 
535
532
  const notePayload = {
@@ -4,57 +4,65 @@ import { DataSource } from 'typeorm';
4
4
 
5
5
  @Injectable()
6
6
  export class WorkflowListMasterService extends EntityServiceImpl {
7
- constructor(private readonly dataSource: DataSource) {
7
+ constructor() {
8
8
  super();
9
9
  }
10
10
 
11
11
  async getActionCategoryListByStageId(stageId: number): Promise<any[]> {
12
- const results = await this.dataSource.query(
13
- `
14
- SELECT
15
- ac.name AS name,
16
- ac.logo AS logo,
17
- ac.modalName AS modalName,
18
- a.action_requirement AS actionRequirement
19
- FROM frm_wf_stage_action_mapping sam
20
- JOIN frm_wf_action a ON sam.action_id = a.id
21
- JOIN frm_wf_action_category ac ON a.action_category = ac.id
22
- WHERE sam.stage_id = $1
23
- `,
24
- [stageId],
25
- );
12
+ const stageActionMapping = this.reflectionHelper.getRepoService('StageActionMapping');
13
+
14
+ const results = await stageActionMapping
15
+ .createQueryBuilder("sam")
16
+ .select([
17
+ "ac.name AS name",
18
+ "ac.logo AS logo",
19
+ "ac.modalname AS modalname",
20
+ "a.action_requirement AS actionRequirement",
21
+ ])
22
+ .innerJoin("frm_wf_action", "a", "a.id = sam.action_id")
23
+ .innerJoin("frm_wf_action_category", "ac", "ac.id = a.action_category")
24
+ .where("sam.stage_id = :stageId", { stageId })
25
+ .getRawMany();
26
26
 
27
27
  // Add actionStatus and return formatted output
28
- return results.map((item: any) => ({
28
+ return results.map((item) => ({
29
29
  name: item.name,
30
30
  logo: item.logo,
31
- modalName: item.modalName,
31
+ modalname: item.modalname,
32
32
  actionRequirement: item.actionRequirement,
33
- actionStatus: 'Done',
33
+ actionStatus: "Done",
34
34
  }));
35
35
  }
36
36
 
37
37
  async getStagesByGroup(stageGroupId: number): Promise<any[]> {
38
- const results = await this.dataSource.query(
39
- `SELECT id, full_name FROM frm_wf_stage WHERE stage_group_id = $1`,
40
- [stageGroupId],
41
- );
42
- return results;
38
+ let stageRepo = this.reflectionHelper.getRepoService('Stage');
39
+
40
+ const results = await stageRepo.find({
41
+ where: {
42
+ stage_group_id: stageGroupId
43
+ }
44
+ });
45
+
46
+ return results.map(stage => ({
47
+ id: stage.id,
48
+ full_name: stage.full_name,
49
+ }));
43
50
  }
44
51
 
45
52
  async getModes(loggedInUser): Promise<any[]> {
46
53
  const { organization_id } = loggedInUser;
47
54
 
48
- const modes = await this.dataSource.query(
49
- `
50
- SELECT id, name
51
- FROM frm_list_master_items
52
- WHERE listtype = 'MOD'
53
- AND organization_id = $1
54
- `,
55
- [organization_id],
56
- );
57
-
58
- return modes;
55
+ let listMasterItemsRepo = this.reflectionHelper.getRepoService('ListMasterItems');
56
+ const modes = await listMasterItemsRepo.find({
57
+ where: {
58
+ listtype: 'MOD',
59
+ organization_id
60
+ }
61
+ });
62
+
63
+ return modes.map(mode => ({
64
+ id: mode.id,
65
+ name: mode.name,
66
+ }));
59
67
  }
60
68
  }
@@ -1,15 +1,10 @@
1
- import {
2
- BadGatewayException,
3
- Inject,
4
- Injectable,
5
- Logger,
6
- } from '@nestjs/common';
1
+ import { Inject, Injectable } from '@nestjs/common';
7
2
  import { ConfigService } from '@nestjs/config';
8
3
  import { InjectRepository } from '@nestjs/typeorm';
9
4
  import axios from 'axios';
10
5
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
11
6
  import { UserData } from 'src/module/user/entity/user.entity';
12
- import { DataSource, Repository } from 'typeorm';
7
+ import { In, Repository } from 'typeorm';
13
8
  import { StageMovementData } from '../entity/stage-movement-data.entity';
14
9
  import { ACTIVITY_CATEGORIES } from '../repository/activity-log.repository';
15
10
  import { StageMovementRepository } from '../repository/stage-movement.repository';
@@ -20,6 +15,8 @@ import { EntityModificationService } from './entity-modification.service';
20
15
  import { TaskService } from './task.service';
21
16
  import { ActionCategory } from '../entity/action-category.entity';
22
17
  import { StageGroup } from '../entity/stage-group.entity';
18
+ import { ActionDataEntity } from '../entity/action-data.entity';
19
+ import { TaskDataEntity } from '../entity/task-data.entity';
23
20
 
24
21
  @Injectable()
25
22
  export class WorkflowMetaService extends EntityServiceImpl {
@@ -27,7 +24,6 @@ export class WorkflowMetaService extends EntityServiceImpl {
27
24
  @InjectRepository(StageMovementData)
28
25
  private readonly stageMovementRepo: Repository<StageMovementData>,
29
26
  private readonly stageMovementRepository: StageMovementRepository,
30
- private readonly dataSource: DataSource,
31
27
  private readonly taskRepository: TaskRepository,
32
28
  private readonly actionDataService: ActionDataService,
33
29
  @Inject('TaskService')
@@ -41,6 +37,10 @@ export class WorkflowMetaService extends EntityServiceImpl {
41
37
  private readonly actionCategoryRepo: Repository<ActionCategory>,
42
38
  @InjectRepository(StageGroup)
43
39
  private readonly stageGroupRepo: Repository<StageGroup>,
40
+ @InjectRepository(ActionDataEntity)
41
+ private readonly actionDataEntityRepository:Repository<ActionDataEntity>,
42
+ @InjectRepository(TaskDataEntity)
43
+ private readonly taskDataEntityRepository:Repository<TaskDataEntity>,
44
44
  ) {
45
45
  super();
46
46
  }
@@ -92,7 +92,7 @@ export class WorkflowMetaService extends EntityServiceImpl {
92
92
  if (!latestMovement) return null;
93
93
 
94
94
  let stageGroup = await this.stageGroupRepo.findOne({
95
- where: {id: latestMovement?.stage_group_id}
95
+ where: { id: latestMovement?.stage_group_id },
96
96
  });
97
97
 
98
98
  return {
@@ -103,7 +103,7 @@ export class WorkflowMetaService extends EntityServiceImpl {
103
103
 
104
104
  // get group name for the current stage
105
105
  const stageGroup = await this.stageGroupRepo.findOne({
106
- where: {id: currentStage?.stage_group_id}
106
+ where: { id: currentStage?.stage_group_id },
107
107
  });
108
108
 
109
109
  // Return the found or newly created current stage movement
@@ -132,8 +132,8 @@ export class WorkflowMetaService extends EntityServiceImpl {
132
132
  const stageGroup = await this.stageGroupRepo.findOne({
133
133
  where: {
134
134
  id: nextStage?.stage_group_id,
135
- }
136
- })
135
+ },
136
+ });
137
137
 
138
138
  return {
139
139
  hasNextStage: !!nextStage,
@@ -227,8 +227,8 @@ export class WorkflowMetaService extends EntityServiceImpl {
227
227
  const actionCategory = await actionCategoryRepo.findOne({
228
228
  where: {
229
229
  id: Number(action.action_category),
230
- }
231
- })
230
+ },
231
+ });
232
232
 
233
233
  if (actionCategory?.code == 'SGCP') {
234
234
  await this.taskRepository.updateTaskStatus(
@@ -339,17 +339,17 @@ export class WorkflowMetaService extends EntityServiceImpl {
339
339
 
340
340
  const actionCategory = await this.actionCategoryRepo.findOne({
341
341
  where: {
342
- id: Number(firstAction.action_category)
343
- }
344
- })
342
+ id: Number(firstAction.action_category),
343
+ },
344
+ });
345
345
 
346
346
  const listMasterItemsRepo = this.reflectionHelper.getRepoService('ListMasterItems');
347
347
 
348
348
  const assignmentType = await listMasterItemsRepo.findOne({
349
349
  where: {
350
- id:Number(firstAction.assignment_type)
351
- }
352
- })
350
+ id: Number(firstAction.assignment_type),
351
+ },
352
+ });
353
353
 
354
354
  // save in action data
355
355
  await this.actionDataService.saveActionData(
@@ -413,13 +413,14 @@ export class WorkflowMetaService extends EntityServiceImpl {
413
413
  loggedInUser,
414
414
  );
415
415
 
416
- const unassignedListMasterItemData = await this.dataSource.query(
417
- `SELECT name, id
418
- FROM frm_list_master_items
419
- WHERE listtype = "LEST" AND organization_id = $1
420
- AND value IN ($2, $3)`,
421
- [loggedInUser.organization_id, 'unassigned', 'active'],
422
- );
416
+ const listMasterItemsRepo = this.reflectionHelper.getRepoService('ListMasterItems');
417
+ const unassignedListMasterItemData = await listMasterItemsRepo.find({
418
+ where: {
419
+ listtype: 'LEST',
420
+ organization_id: loggedInUser.organization_id,
421
+ value: In(['unassigned', 'active'])
422
+ }
423
+ });
423
424
 
424
425
  // Find the IDs explicitly
425
426
  const unassignedId = unassignedListMasterItemData.find(
@@ -444,50 +445,54 @@ export class WorkflowMetaService extends EntityServiceImpl {
444
445
  loggedInUser,
445
446
  );
446
447
 
447
- await this.dataSource.query(
448
- `UPDATE frm_wf_action_data SET user_id =$1
449
- WHERE mapped_entity_id=$2
450
- AND mapped_entity_type = $3
451
- AND stage_id = $4
452
- AND (is_current = 'Y' OR is_current IS NULL)
453
- `,
454
- [lead_owner, lead_id, entity_type, stage_id],
455
- );
456
-
457
- await this.dataSource.query(
458
- `UPDATE crm_lead_meeting SET user_id=$1
459
- WHERE stage_id = $2
460
- AND mapped_entity_id = $3
461
- AND mapped_entity_type = "LEAD"
462
- AND (status='scheduled' OR status='rescheduled')
463
- `,
464
- [lead_owner, stage_id, lead_id],
465
- );
466
-
467
- const taskRows = await this.dataSource.query(
468
- `SELECT id,status FROM frm_wf_task_data
469
- WHERE mapped_entity_id = $1
470
- AND mapped_entity_type = $2
471
- AND stage_id = $3`,
472
- [lead_id, entity_type, stage_id],
473
- );
448
+ await this.actionDataEntityRepository
449
+ .createQueryBuilder()
450
+ .update()
451
+ .set({ user_id: lead_owner })
452
+ .where("mapped_entity_id = :leadId", { leadId: lead_id })
453
+ .andWhere("mapped_entity_type = :entityType", { entityType: entity_type })
454
+ .andWhere("stage_id = :stageId", { stageId: stage_id })
455
+ .andWhere("(is_current = 'Y' OR is_current IS NULL)")
456
+ .execute();
457
+
458
+ const leadMeetingRepo = this.reflectionHelper.getRepoService('LeadScheduleMeet');
459
+
460
+ await leadMeetingRepo
461
+ .createQueryBuilder()
462
+ .update()
463
+ .set({ user_id: lead_owner })
464
+ .where("stage_id = :stageId", { stageId: stage_id })
465
+ .andWhere("mapped_entity_id = :leadId", { leadId: lead_id })
466
+ .andWhere("mapped_entity_type = :entityType", { entityType: "LEAD" })
467
+ .andWhere("(status = 'scheduled' OR status = 'rescheduled')")
468
+ .execute();
469
+
470
+ const taskRows = await this.taskDataEntityRepository.find({
471
+ where: {
472
+ mapped_entity_id: lead_id,
473
+ mapped_entity_type: entity_type,
474
+ stage_id
475
+ }
476
+ });
474
477
 
475
478
  for (const task of taskRows) {
476
- const statusRows = await this.dataSource.query(
477
- `SELECT value FROM frm_list_master_items
478
- WHERE id = $1 AND organization_id = $2`,
479
- [task.status, loggedInUser.organization_id],
480
- );
479
+ const statusRows = await listMasterItemsRepo.findOne({
480
+ where: {
481
+ id: task.status,
482
+ organization_id: loggedInUser.organization_id
483
+ }
484
+ });
481
485
 
482
- const statusName = statusRows[0]?.value?.toLowerCase() || '';
486
+ const statusName = statusRows?.value?.toLowerCase() || '';
483
487
  if (
484
488
  ['todo', 'in_progress'].includes(statusName) ||
485
489
  statusName === 'todo'
486
490
  ) {
487
- await this.dataSource.query(
488
- `UPDATE frm_wf_task_data SET user_id = $1, task_owner = $2 WHERE id = $3`,
489
- [lead_owner, lead_owner, task.id],
490
- );
491
+
492
+ await this.taskDataEntityRepository.update(task.id,{
493
+ user_id: lead_owner,
494
+ task_owner: lead_owner
495
+ });
491
496
  }
492
497
  }
493
498
 
@@ -572,19 +577,18 @@ export class WorkflowMetaService extends EntityServiceImpl {
572
577
 
573
578
  // 2) Find the last assigned *eligible* owner (use IN (...))
574
579
  const placeholders = userIds.map(() => '?').join(',');
575
- const lastRow: Array<{ lead_owner: number }> = await this.dataSource.query(
576
- `
577
- SELECT lead_owner
578
- FROM crm_lead
579
- WHERE organization_id = $1
580
- AND level_id = $2
581
- AND level_type = $3
582
- AND lead_owner IN (${placeholders})
583
- ORDER BY created_date DESC
584
- LIMIT 1
585
- `,
586
- [organization_id, Number(level_id), level_type, ...userIds],
587
- );
580
+
581
+ const leadRepo = this.reflectionHelper.getRepoService('CRMLead');
582
+ const lastRow = await leadRepo
583
+ .createQueryBuilder("cl")
584
+ .select("cl.lead_owner", "lead_owner")
585
+ .where("cl.organization_id = :orgId", { orgId: organization_id })
586
+ .andWhere("cl.level_id = :levelId", { levelId: Number(level_id) })
587
+ .andWhere("cl.level_type = :levelType", { levelType: level_type })
588
+ .andWhere("cl.lead_owner IN (:...owners)", { owners: userIds })
589
+ .orderBy("cl.created_date", "DESC")
590
+ .limit(1)
591
+ .getRawOne();
588
592
 
589
593
  const lastAssigned = lastRow.length ? Number(lastRow[0].lead_owner) : null;
590
594