drapcode-utility 2.4.4 → 2.4.5
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.
|
@@ -3,4 +3,11 @@ export declare const callCurlRequest: (setting: any, user?: any, tenant?: any, u
|
|
|
3
3
|
status: number;
|
|
4
4
|
success: boolean;
|
|
5
5
|
headers: {};
|
|
6
|
+
mysqlError: {};
|
|
7
|
+
} | {
|
|
8
|
+
data: any;
|
|
9
|
+
status: number;
|
|
10
|
+
success: boolean;
|
|
11
|
+
headers: {};
|
|
12
|
+
mysqlError?: undefined;
|
|
6
13
|
}>;
|
|
@@ -146,6 +146,13 @@ const callCurlRequest = async (setting, user = {}, tenant = {}, userSetting = {}
|
|
|
146
146
|
const { setting: extDbSetting } = dtoExternalDb;
|
|
147
147
|
data["searchQuery"] = dtoSearchString;
|
|
148
148
|
result = await makeMySqlCall(projectId, data, extDbSetting);
|
|
149
|
+
if (!result) {
|
|
150
|
+
const errorMessage = "No Response from MySQL Server";
|
|
151
|
+
return prepareReturnObject(errorMessage);
|
|
152
|
+
}
|
|
153
|
+
drapcode_logger_1.logger.info(`MySQL result.status: ${result?.status}`, { label: projectId });
|
|
154
|
+
deleteLocalFiles(isMultipart, toDeleteFiles);
|
|
155
|
+
return prepareReturnObject(result.data, result.status, result?.success || (result.status >= 200 && result.status < 300), result?.headers, result?.mysqlError);
|
|
149
156
|
}
|
|
150
157
|
else {
|
|
151
158
|
result = await makeAxiosCall(projectId, methodType, url, headerValue, data, timeout, wrapJsonDataInArray, awsSignPluginConfig);
|
|
@@ -208,13 +215,24 @@ const deleteLocalFiles = (isMultipart, toDeleteFiles) => {
|
|
|
208
215
|
});
|
|
209
216
|
}
|
|
210
217
|
};
|
|
211
|
-
const prepareReturnObject = (data, status = 400, success = false, headers = {}) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
const prepareReturnObject = (data, status = 400, success = false, headers = {}, mysqlError = {}) => {
|
|
219
|
+
if (mysqlError && Object.keys(mysqlError).length > 0) {
|
|
220
|
+
return {
|
|
221
|
+
data,
|
|
222
|
+
status,
|
|
223
|
+
success,
|
|
224
|
+
headers,
|
|
225
|
+
mysqlError
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return {
|
|
230
|
+
data,
|
|
231
|
+
status,
|
|
232
|
+
success,
|
|
233
|
+
headers
|
|
234
|
+
};
|
|
235
|
+
}
|
|
218
236
|
};
|
|
219
237
|
const makeAxiosCall = async (projectId, methodType, url, axiosConfig, data, timeout, wrapJsonDataInArray, awsSignPluginConfig) => {
|
|
220
238
|
axiosConfig = { url, method: methodType, ...axiosConfig };
|
|
@@ -334,6 +352,7 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
334
352
|
totalRecords: total,
|
|
335
353
|
lastInsertedId: insertedId,
|
|
336
354
|
lastUpdatedId: updatedId,
|
|
355
|
+
lastModifiedId: insertedId || updatedId,
|
|
337
356
|
returned: Array.isArray(rows) ? rows.length : 0
|
|
338
357
|
},
|
|
339
358
|
totalRecords: total,
|
|
@@ -342,7 +361,12 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
342
361
|
}
|
|
343
362
|
catch (err) {
|
|
344
363
|
console.error(`==> MySQL projectID: ${projectId} ~ err:`, err);
|
|
345
|
-
|
|
364
|
+
result = {
|
|
365
|
+
status: 500,
|
|
366
|
+
success: false,
|
|
367
|
+
mysqlError: err
|
|
368
|
+
};
|
|
369
|
+
return result;
|
|
346
370
|
}
|
|
347
371
|
finally {
|
|
348
372
|
await connection.end();
|
|
@@ -352,6 +376,6 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
352
376
|
}
|
|
353
377
|
catch (error) {
|
|
354
378
|
console.error(`==> MySQL projectID: ${projectId} ~ error:`, error);
|
|
355
|
-
return { status: 500, error };
|
|
379
|
+
return { status: 500, success: false, data: {}, mysqlError: error };
|
|
356
380
|
}
|
|
357
381
|
};
|