rez_core 4.0.131 → 4.0.132
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/.idea/250218_nodejs_core.iml +12 -0
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/dist/module/integration/service/wrapper.service.d.ts +3 -1
- package/dist/module/integration/service/wrapper.service.js +39 -36
- package/dist/module/integration/service/wrapper.service.js.map +1 -1
- package/dist/module/mapper/service/field-mapper.service.js +2 -2
- package/dist/module/mapper/service/field-mapper.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/service/loggingUtil.service.d.ts +9 -2
- package/dist/utils/service/loggingUtil.service.js +65 -14
- package/dist/utils/service/loggingUtil.service.js.map +1 -1
- package/dist/utils/utils.module.js +2 -0
- package/dist/utils/utils.module.js.map +1 -1
- package/package.json +1 -1
- package/src/module/integration/service/wrapper.service.ts +248 -41
- package/src/module/mapper/service/field-mapper.service.ts +12 -7
- package/src/utils/service/loggingUtil.service.ts +70 -16
- package/src/utils/utils.module.ts +2 -0
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
1
2
|
export declare class LoggingService {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
private readonly configService;
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly graylogUrl;
|
|
6
|
+
private readonly environment;
|
|
7
|
+
constructor(configService: ConfigService);
|
|
8
|
+
log(level: string, serviceName: string, methodName: string, message: string, parameters?: unknown[], debugInfo?: unknown[]): Promise<void>;
|
|
9
|
+
private sendToGraylog;
|
|
10
|
+
private mapLogLevel;
|
|
4
11
|
}
|
|
@@ -8,29 +8,80 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var LoggingService_1;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.LoggingService = void 0;
|
|
13
14
|
const common_1 = require("@nestjs/common");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const axios_1 = require("axios");
|
|
17
|
+
let LoggingService = LoggingService_1 = class LoggingService {
|
|
18
|
+
constructor(configService) {
|
|
19
|
+
this.configService = configService;
|
|
20
|
+
this.logger = new common_1.Logger(LoggingService_1.name);
|
|
21
|
+
this.graylogUrl =
|
|
22
|
+
this.configService.get('GRAYLOG_URL') ||
|
|
23
|
+
'http://localhost:12201/gelf';
|
|
24
|
+
this.environment = this.configService.get('PROFILE') || 'dev';
|
|
25
|
+
}
|
|
26
|
+
async log(level, serviceName, methodName, message, parameters, debugInfo) {
|
|
27
|
+
const logLevel = level.toLowerCase().trim();
|
|
28
|
+
const logMessage = `${serviceName}.${methodName}: ${message} | Params: ${JSON.stringify(parameters)} | Debug: ${JSON.stringify(debugInfo)}`;
|
|
29
|
+
switch (logLevel) {
|
|
30
|
+
case 'debug':
|
|
31
|
+
case 'info':
|
|
32
|
+
this.logger.debug(logMessage);
|
|
33
|
+
break;
|
|
34
|
+
case 'warn':
|
|
35
|
+
this.logger.warn(logMessage);
|
|
36
|
+
break;
|
|
37
|
+
case 'error':
|
|
38
|
+
this.logger.error(logMessage);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
this.logger.log(logMessage);
|
|
22
42
|
}
|
|
23
|
-
|
|
24
|
-
|
|
43
|
+
this.sendToGraylog({
|
|
44
|
+
version: '1.1',
|
|
45
|
+
host: serviceName || 'nestjs-app',
|
|
46
|
+
short_message: message,
|
|
47
|
+
full_message: logMessage,
|
|
48
|
+
level: this.mapLogLevel(logLevel),
|
|
49
|
+
_service: serviceName,
|
|
50
|
+
_method: methodName,
|
|
51
|
+
_parameters: parameters,
|
|
52
|
+
_debug: debugInfo,
|
|
53
|
+
_environment: this.environment,
|
|
54
|
+
timestamp: Date.now() / 1000,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async sendToGraylog(payload) {
|
|
58
|
+
try {
|
|
59
|
+
await axios_1.default.post(this.graylogUrl, payload, {
|
|
60
|
+
headers: { 'Content-Type': 'application/json' },
|
|
61
|
+
timeout: 2000,
|
|
62
|
+
});
|
|
25
63
|
}
|
|
26
|
-
|
|
27
|
-
logger.
|
|
64
|
+
catch (err) {
|
|
65
|
+
this.logger.warn(`Graylog send failed: ${err.message}`);
|
|
28
66
|
}
|
|
29
67
|
}
|
|
68
|
+
mapLogLevel(level) {
|
|
69
|
+
const mapping = {
|
|
70
|
+
emerg: 0,
|
|
71
|
+
alert: 1,
|
|
72
|
+
crit: 2,
|
|
73
|
+
error: 3,
|
|
74
|
+
warn: 4,
|
|
75
|
+
notice: 5,
|
|
76
|
+
info: 6,
|
|
77
|
+
debug: 7,
|
|
78
|
+
};
|
|
79
|
+
return mapping[level] ?? 6;
|
|
80
|
+
}
|
|
30
81
|
};
|
|
31
82
|
exports.LoggingService = LoggingService;
|
|
32
|
-
exports.LoggingService = LoggingService = __decorate([
|
|
83
|
+
exports.LoggingService = LoggingService = LoggingService_1 = __decorate([
|
|
33
84
|
(0, common_1.Injectable)(),
|
|
34
|
-
__metadata("design:paramtypes", [])
|
|
85
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
35
86
|
], LoggingService);
|
|
36
87
|
//# sourceMappingURL=loggingUtil.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggingUtil.service.js","sourceRoot":"","sources":["../../../src/utils/service/loggingUtil.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loggingUtil.service.js","sourceRoot":"","sources":["../../../src/utils/service/loggingUtil.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -13,12 +13,14 @@ const reflection_helper_service_1 = require("./service/reflection-helper.service
|
|
|
13
13
|
const excelUtil_service_1 = require("./service/excelUtil.service");
|
|
14
14
|
const clockIDGenUtil_service_1 = require("./service/clockIDGenUtil.service");
|
|
15
15
|
const wbsCodeGen_service_1 = require("./service/wbsCodeGen.service");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
16
17
|
let UtilsModule = class UtilsModule {
|
|
17
18
|
};
|
|
18
19
|
exports.UtilsModule = UtilsModule;
|
|
19
20
|
exports.UtilsModule = UtilsModule = __decorate([
|
|
20
21
|
(0, common_1.Global)(),
|
|
21
22
|
(0, common_1.Module)({
|
|
23
|
+
imports: [config_1.ConfigModule],
|
|
22
24
|
providers: [
|
|
23
25
|
loggingUtil_service_1.LoggingService,
|
|
24
26
|
reflection_helper_service_1.ReflectionHelper,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.module.js","sourceRoot":"","sources":["../../src/utils/utils.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,uEAA+D;AAC/D,mFAAuE;AACvE,mEAAwD;AACxD,6EAAqE;AACrE,qEAAiE;
|
|
1
|
+
{"version":3,"file":"utils.module.js","sourceRoot":"","sources":["../../src/utils/utils.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,uEAA+D;AAC/D,mFAAuE;AACvE,mEAAwD;AACxD,6EAAqE;AACrE,qEAAiE;AACjE,2CAA8C;AAoBvC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IAlBvB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAY,CAAC;QACvB,SAAS,EAAE;YACT,oCAAc;YACd,4CAAgB;YAChB,6BAAS;YACT,0CAAiB;YACjB,sCAAiB;SAClB;QACD,OAAO,EAAE;YACP,oCAAc;YACd,4CAAgB;YAChB,6BAAS;YACT,0CAAiB;YACjB,sCAAiB;SAClB;KACF,CAAC;GACW,WAAW,CAAG"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|
|
3
3
|
import { GenericMessageDto, IntegrationService } from './integration.service';
|
|
4
4
|
import { GoogleService } from './calendar-event.service';
|
|
5
5
|
import { IcsMeetingService } from 'src/module/ics/service/ics.service';
|
|
6
|
+
import { LoggingService } from 'src/utils/service/loggingUtil.service';
|
|
6
7
|
|
|
7
8
|
@Injectable()
|
|
8
9
|
export class WrapperService {
|
|
@@ -13,6 +14,7 @@ export class WrapperService {
|
|
|
13
14
|
private readonly integrationService: IntegrationService,
|
|
14
15
|
private readonly googleService: GoogleService,
|
|
15
16
|
private readonly icsService: IcsMeetingService,
|
|
17
|
+
private readonly loggingService: LoggingService,
|
|
16
18
|
) {}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -20,15 +22,27 @@ export class WrapperService {
|
|
|
20
22
|
*/
|
|
21
23
|
async sendMailWrapper(payload: any, loggedInUser: any) {
|
|
22
24
|
try {
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
+
this.loggingService.log(
|
|
26
|
+
'debug',
|
|
27
|
+
'wrapperService',
|
|
28
|
+
'sendMailWrapper',
|
|
29
|
+
`sendMailWrapper called. User: ${JSON.stringify(
|
|
30
|
+
loggedInUser,
|
|
31
|
+
)}, Payload: ${JSON.stringify(payload)}`,
|
|
32
|
+
[],
|
|
33
|
+
[],
|
|
25
34
|
);
|
|
26
35
|
|
|
27
36
|
const { level_id, level_type, organization_id } = loggedInUser;
|
|
28
37
|
|
|
29
38
|
// 1. Check for config at user’s level
|
|
30
|
-
this.
|
|
39
|
+
this.loggingService.log(
|
|
40
|
+
'debug',
|
|
41
|
+
'wrapperService',
|
|
42
|
+
'sendMailWrapper',
|
|
31
43
|
`Fetching configs for level_id=${level_id}, level_type=${level_type}`,
|
|
44
|
+
[],
|
|
45
|
+
[],
|
|
32
46
|
);
|
|
33
47
|
const configs = await this.datasource.query(
|
|
34
48
|
`SELECT * FROM frm_integration_config
|
|
@@ -38,27 +52,51 @@ export class WrapperService {
|
|
|
38
52
|
AND integration_type = 'EMAIL'`,
|
|
39
53
|
[level_id, level_type],
|
|
40
54
|
);
|
|
41
|
-
|
|
55
|
+
|
|
56
|
+
this.loggingService.log(
|
|
57
|
+
'debug',
|
|
58
|
+
'wrapperService',
|
|
59
|
+
'sendMailWrapper',
|
|
60
|
+
`Configs found: ${JSON.stringify(configs)}`,
|
|
61
|
+
[],
|
|
62
|
+
[],
|
|
63
|
+
);
|
|
42
64
|
|
|
43
65
|
let templateCode: string | undefined;
|
|
44
66
|
|
|
45
67
|
if (payload.templateCode) {
|
|
46
|
-
this.
|
|
68
|
+
this.loggingService.log(
|
|
69
|
+
'debug',
|
|
70
|
+
'wrapperService',
|
|
71
|
+
'sendMailWrapper',
|
|
47
72
|
`Looking up templateCode=${payload.templateCode} for current level`,
|
|
73
|
+
[],
|
|
74
|
+
[],
|
|
48
75
|
);
|
|
76
|
+
|
|
49
77
|
const template = await this.datasource.query(
|
|
50
78
|
`SELECT rich_text FROM frm_wf_comm_template WHERE code = ? AND level_id = ? AND level_type = ? LIMIT 1`,
|
|
51
79
|
[payload.templateCode, level_id, level_type],
|
|
52
80
|
);
|
|
53
|
-
this.
|
|
81
|
+
this.loggingService.log(
|
|
82
|
+
'debug',
|
|
83
|
+
'wrapperService',
|
|
84
|
+
'sendMailWrapper',
|
|
54
85
|
`Template lookup result: ${JSON.stringify(template)}`,
|
|
86
|
+
[],
|
|
87
|
+
[],
|
|
55
88
|
);
|
|
56
89
|
|
|
57
90
|
if (template && template.length > 0) {
|
|
58
91
|
templateCode = template[0]?.rich_text;
|
|
59
92
|
} else {
|
|
60
|
-
this.
|
|
93
|
+
this.loggingService.log(
|
|
94
|
+
'warn',
|
|
95
|
+
'wrapperService',
|
|
96
|
+
'sendMailWrapper',
|
|
61
97
|
`No template found for templateCode=${payload.templateCode} and current level`,
|
|
98
|
+
[],
|
|
99
|
+
[],
|
|
62
100
|
);
|
|
63
101
|
}
|
|
64
102
|
}
|
|
@@ -66,7 +104,15 @@ export class WrapperService {
|
|
|
66
104
|
let payloadSendMail: GenericMessageDto;
|
|
67
105
|
|
|
68
106
|
if (configs && configs.length > 0) {
|
|
69
|
-
this.
|
|
107
|
+
this.loggingService.log(
|
|
108
|
+
'debug',
|
|
109
|
+
'wrapperService',
|
|
110
|
+
'sendMailWrapper',
|
|
111
|
+
`Using user-level configs`,
|
|
112
|
+
[],
|
|
113
|
+
[],
|
|
114
|
+
);
|
|
115
|
+
|
|
70
116
|
payloadSendMail = {
|
|
71
117
|
levelId: level_id,
|
|
72
118
|
levelType: level_type,
|
|
@@ -84,21 +130,40 @@ export class WrapperService {
|
|
|
84
130
|
organization_id: loggedInUser.organization_id,
|
|
85
131
|
};
|
|
86
132
|
} else {
|
|
87
|
-
this.
|
|
133
|
+
this.loggingService.log(
|
|
134
|
+
'warn',
|
|
135
|
+
'wrapperService',
|
|
136
|
+
'sendMailWrapper',
|
|
88
137
|
`No user-level configs found. Falling back to ORG-level`,
|
|
138
|
+
[],
|
|
139
|
+
[],
|
|
89
140
|
);
|
|
141
|
+
|
|
90
142
|
const fallbackConfigs = await this.datasource.query(
|
|
91
143
|
`SELECT * FROM frm_integration_config
|
|
92
144
|
WHERE level_type = 'ORG'
|
|
93
145
|
AND integration_type = 'EMAIL'
|
|
94
146
|
AND status = 1`,
|
|
95
147
|
);
|
|
96
|
-
|
|
148
|
+
|
|
149
|
+
this.loggingService.log(
|
|
150
|
+
'debug',
|
|
151
|
+
'wrapperService',
|
|
152
|
+
'sendMailWrapper',
|
|
97
153
|
`ORG-level configs: ${JSON.stringify(fallbackConfigs)}`,
|
|
154
|
+
[],
|
|
155
|
+
[],
|
|
98
156
|
);
|
|
99
157
|
|
|
100
158
|
if (!fallbackConfigs || fallbackConfigs.length === 0) {
|
|
101
|
-
this.
|
|
159
|
+
this.loggingService.log(
|
|
160
|
+
'warn',
|
|
161
|
+
'wrapperService',
|
|
162
|
+
'sendMailWrapper',
|
|
163
|
+
'No active email communication config found',
|
|
164
|
+
[],
|
|
165
|
+
[],
|
|
166
|
+
);
|
|
102
167
|
}
|
|
103
168
|
|
|
104
169
|
payloadSendMail = {
|
|
@@ -119,15 +184,27 @@ export class WrapperService {
|
|
|
119
184
|
};
|
|
120
185
|
}
|
|
121
186
|
|
|
122
|
-
this.
|
|
123
|
-
|
|
187
|
+
this.loggingService.log(
|
|
188
|
+
'debug',
|
|
189
|
+
'wrapperService',
|
|
190
|
+
'sendMailWrapper',
|
|
191
|
+
`Final payload for IntegrationService: ${JSON.stringify(
|
|
192
|
+
payloadSendMail,
|
|
193
|
+
)}`,
|
|
194
|
+
[],
|
|
195
|
+
[],
|
|
124
196
|
);
|
|
125
197
|
|
|
126
198
|
const result =
|
|
127
199
|
await this.integrationService.sendGenericMessage(payloadSendMail);
|
|
128
200
|
|
|
129
|
-
this.
|
|
201
|
+
this.loggingService.log(
|
|
202
|
+
'log',
|
|
203
|
+
'wrapperService',
|
|
204
|
+
'sendMailWrapper',
|
|
130
205
|
`sendMailWrapper SUCCESS. Result: ${JSON.stringify(result)}`,
|
|
206
|
+
[],
|
|
207
|
+
[],
|
|
131
208
|
);
|
|
132
209
|
|
|
133
210
|
return {
|
|
@@ -135,7 +212,14 @@ export class WrapperService {
|
|
|
135
212
|
data: result,
|
|
136
213
|
};
|
|
137
214
|
} catch (error: any) {
|
|
138
|
-
this.
|
|
215
|
+
this.loggingService.log(
|
|
216
|
+
'error',
|
|
217
|
+
'wrapperService',
|
|
218
|
+
'sendMailWrapper',
|
|
219
|
+
`sendMailWrapper ERROR: ${error.message}`,
|
|
220
|
+
[],
|
|
221
|
+
[error.stack], // Sending stack trace as additional data
|
|
222
|
+
);
|
|
139
223
|
return {
|
|
140
224
|
success: false,
|
|
141
225
|
error: error.message,
|
|
@@ -149,17 +233,29 @@ export class WrapperService {
|
|
|
149
233
|
|
|
150
234
|
async sendCommunicationWrapperService(entity: any, loggedInUser: any) {
|
|
151
235
|
try {
|
|
152
|
-
this.
|
|
236
|
+
this.loggingService.log(
|
|
237
|
+
'log',
|
|
238
|
+
'wrapperService',
|
|
239
|
+
'sendCommunicationWrapperService',
|
|
153
240
|
`sendCommunicationWrapper called. User: ${JSON.stringify(
|
|
154
241
|
loggedInUser,
|
|
155
242
|
)}, Payload: ${JSON.stringify(entity)}`,
|
|
243
|
+
[],
|
|
244
|
+
[],
|
|
156
245
|
);
|
|
157
246
|
|
|
158
247
|
const { level_id, level_type, appcode, organization_id } = loggedInUser;
|
|
159
248
|
|
|
160
249
|
// Check if active configs exist for current user's level
|
|
161
|
-
this.
|
|
162
|
-
|
|
250
|
+
this.loggingService.log(
|
|
251
|
+
'debug',
|
|
252
|
+
'wrapperService',
|
|
253
|
+
'sendCommunicationWrapperService',
|
|
254
|
+
`Checking active ${
|
|
255
|
+
entity.type || 'EMAIL'
|
|
256
|
+
} configs for level_id=${level_id}, level_type=${level_type}, app_code=${appcode}`,
|
|
257
|
+
[],
|
|
258
|
+
[],
|
|
163
259
|
);
|
|
164
260
|
|
|
165
261
|
let configs = await this.integrationService.getActiveConfigs(
|
|
@@ -174,8 +270,13 @@ export class WrapperService {
|
|
|
174
270
|
|
|
175
271
|
// Fallback to ORG-level if no configs found
|
|
176
272
|
if (!configs || configs.length === 0) {
|
|
177
|
-
this.
|
|
273
|
+
this.loggingService.log(
|
|
274
|
+
'warn',
|
|
275
|
+
'wrapperService',
|
|
276
|
+
'sendCommunicationWrapperService',
|
|
178
277
|
`No active configs found for ${level_type}:${level_id}, falling back to ORG-level`,
|
|
278
|
+
[],
|
|
279
|
+
[],
|
|
179
280
|
);
|
|
180
281
|
|
|
181
282
|
configs = await this.integrationService.getActiveConfigs(
|
|
@@ -190,7 +291,14 @@ export class WrapperService {
|
|
|
190
291
|
}
|
|
191
292
|
|
|
192
293
|
if (!configs || configs.length === 0) {
|
|
193
|
-
this.
|
|
294
|
+
this.loggingService.log(
|
|
295
|
+
'error',
|
|
296
|
+
'wrapperService',
|
|
297
|
+
'sendCommunicationWrapperService',
|
|
298
|
+
'No active configurations found at any level.',
|
|
299
|
+
[],
|
|
300
|
+
[],
|
|
301
|
+
);
|
|
194
302
|
throw new Error('No active configurations found.');
|
|
195
303
|
}
|
|
196
304
|
|
|
@@ -198,8 +306,13 @@ export class WrapperService {
|
|
|
198
306
|
let resolvedTemplateId = entity?.templateId;
|
|
199
307
|
|
|
200
308
|
if (entity.template_code) {
|
|
201
|
-
this.
|
|
309
|
+
this.loggingService.log(
|
|
310
|
+
'debug',
|
|
311
|
+
'wrapperService',
|
|
312
|
+
'sendCommunicationWrapperService',
|
|
202
313
|
`Looking up template for code=${entity.template_code}, level_id=${level_id}, level_type=${level_type}`,
|
|
314
|
+
[],
|
|
315
|
+
[],
|
|
203
316
|
);
|
|
204
317
|
|
|
205
318
|
// Try to find template at user's level first
|
|
@@ -214,8 +327,13 @@ export class WrapperService {
|
|
|
214
327
|
|
|
215
328
|
// Fallback to ORG + organization_id if not found
|
|
216
329
|
if (!templates || templates.length === 0) {
|
|
217
|
-
this.
|
|
330
|
+
this.loggingService.log(
|
|
331
|
+
'warn',
|
|
332
|
+
'wrapperService',
|
|
333
|
+
'sendCommunicationWrapperService',
|
|
218
334
|
`No template found for ${entity.template_code} at provided level. Falling back to ORG-level.`,
|
|
335
|
+
[],
|
|
336
|
+
[],
|
|
219
337
|
);
|
|
220
338
|
|
|
221
339
|
templates = await this.datasource.query(
|
|
@@ -230,12 +348,22 @@ export class WrapperService {
|
|
|
230
348
|
|
|
231
349
|
if (templates && templates.length > 0) {
|
|
232
350
|
resolvedTemplateId = templates[0]?.id;
|
|
233
|
-
this.
|
|
351
|
+
this.loggingService.log(
|
|
352
|
+
'debug',
|
|
353
|
+
'wrapperService',
|
|
354
|
+
'sendCommunicationWrapperService',
|
|
234
355
|
`Template resolved for code=${entity.template_code}, id=${resolvedTemplateId}`,
|
|
356
|
+
[],
|
|
357
|
+
[],
|
|
235
358
|
);
|
|
236
359
|
} else {
|
|
237
|
-
this.
|
|
360
|
+
this.loggingService.log(
|
|
361
|
+
'warn',
|
|
362
|
+
'wrapperService',
|
|
363
|
+
'sendCommunicationWrapperService',
|
|
238
364
|
`No template found for code=${entity.template_code} at any level.`,
|
|
365
|
+
[],
|
|
366
|
+
[],
|
|
239
367
|
);
|
|
240
368
|
}
|
|
241
369
|
}
|
|
@@ -261,23 +389,37 @@ export class WrapperService {
|
|
|
261
389
|
organization_id: organization_id,
|
|
262
390
|
} as any;
|
|
263
391
|
|
|
264
|
-
this.
|
|
392
|
+
this.loggingService.log(
|
|
393
|
+
'debug',
|
|
394
|
+
'wrapperService',
|
|
395
|
+
'sendCommunicationWrapperService',
|
|
265
396
|
`Final payload for sendGenericMessage: ${JSON.stringify(mailPayload)}`,
|
|
397
|
+
[],
|
|
398
|
+
[],
|
|
266
399
|
);
|
|
267
400
|
|
|
268
401
|
// Step 5️⃣ Send via Integration Service
|
|
269
402
|
const result =
|
|
270
403
|
await this.integrationService.sendGenericMessage(mailPayload);
|
|
271
404
|
|
|
272
|
-
this.
|
|
405
|
+
this.loggingService.log(
|
|
406
|
+
'log',
|
|
407
|
+
'wrapperService',
|
|
408
|
+
'sendCommunicationWrapperService',
|
|
273
409
|
`sendCommunicationWrapper SUCCESS. Result: ${JSON.stringify(result)}`,
|
|
410
|
+
[],
|
|
411
|
+
[],
|
|
274
412
|
);
|
|
275
413
|
|
|
276
414
|
return result;
|
|
277
415
|
} catch (error: any) {
|
|
278
|
-
this.
|
|
416
|
+
this.loggingService.log(
|
|
417
|
+
'error',
|
|
418
|
+
'wrapperService',
|
|
419
|
+
'sendCommunicationWrapperService',
|
|
279
420
|
`sendCommunicationWrapper ERROR: ${error.message}`,
|
|
280
|
-
|
|
421
|
+
[],
|
|
422
|
+
[error.stack],
|
|
281
423
|
);
|
|
282
424
|
return {
|
|
283
425
|
success: false,
|
|
@@ -296,8 +438,15 @@ export class WrapperService {
|
|
|
296
438
|
mapped_entities?: any,
|
|
297
439
|
) {
|
|
298
440
|
try {
|
|
299
|
-
this.
|
|
300
|
-
|
|
441
|
+
this.loggingService.log(
|
|
442
|
+
'log',
|
|
443
|
+
'wrapperService',
|
|
444
|
+
'scheduleMeetingWrapper',
|
|
445
|
+
`scheduleMeetingWrapper called by user=${
|
|
446
|
+
loggedInUser?.id || 'unknown'
|
|
447
|
+
} Payload=${JSON.stringify(payload)}`,
|
|
448
|
+
[],
|
|
449
|
+
[],
|
|
301
450
|
);
|
|
302
451
|
|
|
303
452
|
// Normalize emails (to, cc, bcc → attendees)
|
|
@@ -342,7 +491,14 @@ export class WrapperService {
|
|
|
342
491
|
}
|
|
343
492
|
|
|
344
493
|
// ---- Step 2: Check ORG-level configs ----
|
|
345
|
-
this.
|
|
494
|
+
this.loggingService.log(
|
|
495
|
+
'log',
|
|
496
|
+
'wrapperService',
|
|
497
|
+
'scheduleMeetingWrapper',
|
|
498
|
+
`No user-level config found, checking ORG-level...`,
|
|
499
|
+
[],
|
|
500
|
+
[],
|
|
501
|
+
);
|
|
346
502
|
|
|
347
503
|
const orgConfigs = await this.datasource.query(
|
|
348
504
|
`SELECT * FROM frm_integration_config
|
|
@@ -361,7 +517,14 @@ export class WrapperService {
|
|
|
361
517
|
'EMAIL',
|
|
362
518
|
);
|
|
363
519
|
|
|
364
|
-
this.
|
|
520
|
+
this.loggingService.log(
|
|
521
|
+
'debug',
|
|
522
|
+
'wrapperService',
|
|
523
|
+
'scheduleMeetingWrapper',
|
|
524
|
+
`ORG configs found: ${JSON.stringify(orgConfigs)}`,
|
|
525
|
+
[],
|
|
526
|
+
[],
|
|
527
|
+
);
|
|
365
528
|
|
|
366
529
|
if (integrationConfig) {
|
|
367
530
|
return {
|
|
@@ -377,9 +540,13 @@ export class WrapperService {
|
|
|
377
540
|
};
|
|
378
541
|
}
|
|
379
542
|
} catch (error: any) {
|
|
380
|
-
this.
|
|
543
|
+
this.loggingService.log(
|
|
544
|
+
'error',
|
|
545
|
+
'wrapperService',
|
|
546
|
+
'scheduleMeetingWrapper',
|
|
381
547
|
`scheduleMeetingWrapper ERROR: ${error.message}`,
|
|
382
|
-
|
|
548
|
+
[],
|
|
549
|
+
[error.stack],
|
|
383
550
|
);
|
|
384
551
|
return { success: false, error: error.message };
|
|
385
552
|
}
|
|
@@ -389,14 +556,28 @@ export class WrapperService {
|
|
|
389
556
|
* Fetch credentials JSON by config ID
|
|
390
557
|
*/
|
|
391
558
|
private async getConfigCred(configId: number) {
|
|
392
|
-
this.
|
|
559
|
+
this.loggingService.log(
|
|
560
|
+
'debug',
|
|
561
|
+
'wrapperService',
|
|
562
|
+
'getConfigCred',
|
|
563
|
+
`Fetching config JSON for configId=${configId}`,
|
|
564
|
+
[],
|
|
565
|
+
[],
|
|
566
|
+
);
|
|
393
567
|
const configRes = await this.datasource.query(
|
|
394
568
|
`SELECT config_json
|
|
395
569
|
FROM frm_integration_config
|
|
396
570
|
WHERE id = ?`,
|
|
397
571
|
[configId],
|
|
398
572
|
);
|
|
399
|
-
this.
|
|
573
|
+
this.loggingService.log(
|
|
574
|
+
'debug',
|
|
575
|
+
'wrapperService',
|
|
576
|
+
'getConfigCred',
|
|
577
|
+
`Config fetch result: ${JSON.stringify(configRes)}`,
|
|
578
|
+
[],
|
|
579
|
+
[],
|
|
580
|
+
);
|
|
400
581
|
return configRes?.[0]?.config_json || null;
|
|
401
582
|
}
|
|
402
583
|
|
|
@@ -408,7 +589,14 @@ export class WrapperService {
|
|
|
408
589
|
organizationId: number,
|
|
409
590
|
mapped_entities?: any,
|
|
410
591
|
) {
|
|
411
|
-
this.
|
|
592
|
+
this.loggingService.log(
|
|
593
|
+
'log',
|
|
594
|
+
'wrapperService',
|
|
595
|
+
'sendIcsInvite',
|
|
596
|
+
`Generating ICS file. Payload: ${JSON.stringify(payload)}`,
|
|
597
|
+
[],
|
|
598
|
+
[],
|
|
599
|
+
);
|
|
412
600
|
|
|
413
601
|
if (payload.template_code) {
|
|
414
602
|
let templates = await this.datasource.query(
|
|
@@ -434,9 +622,16 @@ export class WrapperService {
|
|
|
434
622
|
payload,
|
|
435
623
|
activeConfig?.config_json,
|
|
436
624
|
);
|
|
437
|
-
this.
|
|
625
|
+
this.loggingService.log(
|
|
626
|
+
'debug',
|
|
627
|
+
'wrapperService',
|
|
628
|
+
'sendIcsInvite',
|
|
629
|
+
`ICS generated (base64 length: ${base64String?.length})`,
|
|
630
|
+
[],
|
|
631
|
+
[],
|
|
632
|
+
);
|
|
438
633
|
|
|
439
|
-
//
|
|
634
|
+
// Normalize attendees
|
|
440
635
|
const attendeeEmails =
|
|
441
636
|
payload.attendees?.flatMap((a) =>
|
|
442
637
|
Array.isArray(a.email) ? a.email : [a.email],
|
|
@@ -482,12 +677,24 @@ export class WrapperService {
|
|
|
482
677
|
mapped_entities,
|
|
483
678
|
};
|
|
484
679
|
|
|
485
|
-
this.
|
|
680
|
+
this.loggingService.log(
|
|
681
|
+
'debug',
|
|
682
|
+
'wrapperService',
|
|
683
|
+
'sendIcsInvite',
|
|
486
684
|
`Final payload for ICS send: ${JSON.stringify(payloadSendMail)}`,
|
|
685
|
+
[],
|
|
686
|
+
[],
|
|
487
687
|
);
|
|
488
688
|
const result =
|
|
489
689
|
await this.integrationService.sendGenericMessage(payloadSendMail);
|
|
490
|
-
this.
|
|
690
|
+
this.loggingService.log(
|
|
691
|
+
'log',
|
|
692
|
+
'wrapperService',
|
|
693
|
+
'sendIcsInvite',
|
|
694
|
+
`ICS mail send result: ${JSON.stringify(result)}`,
|
|
695
|
+
[],
|
|
696
|
+
[],
|
|
697
|
+
);
|
|
491
698
|
return result;
|
|
492
699
|
}
|
|
493
700
|
}
|