rez_core 3.1.126 → 3.1.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/integration/service/wrapper.service.d.ts +9 -0
- package/dist/module/integration/service/wrapper.service.js +50 -0
- package/dist/module/integration/service/wrapper.service.js.map +1 -1
- package/dist/module/workflow/controller/stage.controller.d.ts +1 -0
- package/dist/module/workflow/controller/stage.controller.js.map +1 -1
- package/dist/module/workflow/service/stage.service.d.ts +1 -0
- package/dist/module/workflow/service/stage.service.js +22 -2
- package/dist/module/workflow/service/stage.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/integration/service/wrapper.service.ts +92 -4
- package/src/module/workflow/controller/stage.controller.ts +1 -1
- package/src/module/workflow/service/stage.service.ts +40 -2
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Injectable, Logger } from '@nestjs/common';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
|
-
import {
|
|
4
|
-
IntegrationService,
|
|
5
|
-
GenericMessageDto,
|
|
6
|
-
} from './integration.service';
|
|
3
|
+
import { IntegrationService, GenericMessageDto } from './integration.service';
|
|
7
4
|
import { GoogleService } from './calendar-event.service';
|
|
8
5
|
import { IcsMeetingService } from 'src/module/ics/service/ics.service';
|
|
9
6
|
|
|
@@ -144,6 +141,97 @@ export class WrapperService {
|
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Wrapper for sending communication
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
async sendCommunicationWrapperService(entity: any, loggedInUser: any) {
|
|
149
|
+
try {
|
|
150
|
+
this.logger.log(
|
|
151
|
+
`sendMailWrapper called. User: ${JSON.stringify(loggedInUser)}, Payload: ${JSON.stringify(entity)}`,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const { level_id, level_type, appcode } = loggedInUser;
|
|
155
|
+
|
|
156
|
+
// Step 1: Check if active email configs exist for current user's level
|
|
157
|
+
this.logger.debug(
|
|
158
|
+
`Checking active EMAIL configs for level_id=${level_id}, level_type=${level_type}, app_code=${appcode}`,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
let configs = await this.integrationService.getActiveConfigs(
|
|
162
|
+
level_id,
|
|
163
|
+
level_type,
|
|
164
|
+
appcode,
|
|
165
|
+
'EMAIL',
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
let effectiveLevelId = level_id;
|
|
169
|
+
let effectiveLevelType = level_type;
|
|
170
|
+
|
|
171
|
+
// Step 2: If no configs exist, fall back to ORG-level (1, 'ORG')
|
|
172
|
+
if (!configs || configs.length === 0) {
|
|
173
|
+
this.logger.warn(
|
|
174
|
+
`No EMAIL configs found for ${level_type}:${level_id}, falling back to ORG-level`,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
configs = await this.integrationService.getActiveConfigs(
|
|
178
|
+
1,
|
|
179
|
+
'ORG',
|
|
180
|
+
appcode,
|
|
181
|
+
'EMAIL',
|
|
182
|
+
);
|
|
183
|
+
effectiveLevelId = 1;
|
|
184
|
+
effectiveLevelType = 'ORG';
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!configs || configs.length === 0) {
|
|
188
|
+
this.logger.error('No active EMAIL configurations found at any level.');
|
|
189
|
+
throw new Error('No active EMAIL configurations found.');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Step 3: Prepare payload for Integration Service
|
|
193
|
+
const mailPayload = {
|
|
194
|
+
to: entity.to,
|
|
195
|
+
subject: entity.subject,
|
|
196
|
+
html: entity.message,
|
|
197
|
+
cc: entity?.cc,
|
|
198
|
+
bcc: entity?.bcc,
|
|
199
|
+
templateId: entity.templateId,
|
|
200
|
+
message: entity.message,
|
|
201
|
+
type: entity.type || 'EMAIL',
|
|
202
|
+
levelId: effectiveLevelId,
|
|
203
|
+
levelType: effectiveLevelType,
|
|
204
|
+
app_code: appcode,
|
|
205
|
+
user_id: loggedInUser.id,
|
|
206
|
+
entity_type: 'LEAD',
|
|
207
|
+
entity_id: entity.mapped_entity_id,
|
|
208
|
+
} as any;
|
|
209
|
+
|
|
210
|
+
this.logger.debug(
|
|
211
|
+
`Final payload for sendGenericMessage: ${JSON.stringify(mailPayload)}`,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Step 4: Send mail via integration service
|
|
215
|
+
const result =
|
|
216
|
+
await this.integrationService.sendGenericMessage(mailPayload);
|
|
217
|
+
|
|
218
|
+
this.logger.log(
|
|
219
|
+
`sendMailWrapper SUCCESS. Result: ${JSON.stringify(result)}`,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
success: true,
|
|
224
|
+
data: result,
|
|
225
|
+
};
|
|
226
|
+
} catch (error: any) {
|
|
227
|
+
this.logger.error(`sendMailWrapper ERROR: ${error.message}`, error.stack);
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
error: error.message,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
147
235
|
/**
|
|
148
236
|
* Wrapper for scheduling meeting
|
|
149
237
|
*/
|
|
@@ -24,7 +24,7 @@ export class StageController {
|
|
|
24
24
|
@Post('/getAllStage')
|
|
25
25
|
async getAllStage(
|
|
26
26
|
@Req() req: Request & { user: any },
|
|
27
|
-
@Body() body: { stage_group_id: number },
|
|
27
|
+
@Body() body: { stage_group_id: number; mapped_entity_id: number },
|
|
28
28
|
@Query() query: { show_previous: boolean },
|
|
29
29
|
) {
|
|
30
30
|
const { organization_id } = req.user.userData;
|
|
@@ -34,6 +34,7 @@ export class StageService extends EntityServiceImpl {
|
|
|
34
34
|
async getAllStage(
|
|
35
35
|
payload: {
|
|
36
36
|
stage_group_id: number;
|
|
37
|
+
mapped_entity_id: number;
|
|
37
38
|
},
|
|
38
39
|
organization_id: number,
|
|
39
40
|
show_previous: boolean,
|
|
@@ -63,15 +64,52 @@ export class StageService extends EntityServiceImpl {
|
|
|
63
64
|
return allStages;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// 1. Get all stages up to the current stage group
|
|
66
68
|
const allStageWithStageGroup =
|
|
67
69
|
await this.stageRepository.getAllStageGroupAndStageByStageMovement(
|
|
68
70
|
payload.stage_group_id,
|
|
69
71
|
organization_id,
|
|
70
72
|
);
|
|
71
73
|
|
|
72
|
-
|
|
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
|
+
}>('cr_wf_stage_movement_data', {
|
|
83
|
+
where: {
|
|
84
|
+
mapped_entity_id: payload.mapped_entity_id,
|
|
85
|
+
mapped_entity_type: 'LEAD',
|
|
86
|
+
},
|
|
87
|
+
order: { id: 'ASC' },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (!allStageMovementData || allStageMovementData.length === 0) {
|
|
91
|
+
return allStageWithStageGroup;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 3. Find the current stage movement (is_current === 'Y')
|
|
95
|
+
const currentMovement = allStageMovementData.find(
|
|
96
|
+
(m) => m.is_current === 'Y',
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!currentMovement) {
|
|
100
|
+
return allStageWithStageGroup;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 4. Filter stages up to and including the current stage_id
|
|
104
|
+
const filteredStages: any[] = [];
|
|
105
|
+
for (const stage of allStageWithStageGroup) {
|
|
106
|
+
filteredStages.push(stage);
|
|
107
|
+
if (stage.id === currentMovement.stage_id) {
|
|
108
|
+
break; // stop once we reach the current stage
|
|
109
|
+
}
|
|
110
|
+
}
|
|
73
111
|
|
|
74
|
-
return
|
|
112
|
+
return filteredStages;
|
|
75
113
|
}
|
|
76
114
|
|
|
77
115
|
async updateEntity(
|