jr-common-micro 1.1.27 → 1.1.29

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.
@@ -49,7 +49,7 @@ export declare function fetchScrappingData<T>(fetchFn: (params: any) => Promise<
49
49
  data: string;
50
50
  }>): Promise<T>;
51
51
  export declare function getGrpcClient(packageName: string, grpcHost: string, grpcPort: string): import("@nestjs/microservices").ClientGrpcProxy;
52
- export declare function getStatus(codeSuccess: number, codeError: number, logger: any, data: any, text: string, logOnSuccess?: boolean): {
52
+ export declare function getStatus(codeSuccess: number, codeError: number, logger: any, data: any, text: string, logOnSuccess?: boolean, elasticsearchService?: any, elasticsearch_logs_index?: string, methodName?: string): {
53
53
  code: number;
54
54
  };
55
55
  export declare const getPrismaLogMessage: (functionName: string, options?: {
@@ -65,6 +65,6 @@ export declare const getRedisLogMessage: (functionName: string, redis: {
65
65
  data?: any;
66
66
  misc?: Record<string, any>;
67
67
  }) => LogMessage;
68
- export declare function executeWithReturn<T extends (...args: any[]) => any>(logger: any, logMessage: LogMessage, func: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
69
- export declare function executeWithoutReturn<T extends (...args: any[]) => any>(logger: any, logMessage: LogMessage, func: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
68
+ export declare function executeWithReturn<T extends (...args: any[]) => any>(logger: any, logMessage: LogMessage, func: T, elasticsearchService?: any, elasticsearch_logs_index?: string, methodName?: string, ...args: Parameters<T>): Promise<ReturnType<T>>;
69
+ export declare function executeWithoutReturn<T extends (...args: any[]) => any>(logger: any, logMessage: LogMessage, func: T, elasticsearchService?: any, elasticsearch_logs_index?: string, methodName?: string, ...args: Parameters<T>): Promise<ReturnType<T>>;
70
70
  export declare function jsonStringify(val: any): string;
@@ -349,8 +349,17 @@ function getGrpcClient(packageName, grpcHost, grpcPort) {
349
349
  },
350
350
  });
351
351
  }
352
- function getStatus(codeSuccess, codeError, logger, data, text, logOnSuccess = false) {
352
+ function getStatus(codeSuccess, codeError, logger, data, text, logOnSuccess = false, elasticsearchService, elasticsearch_logs_index, methodName) {
353
353
  if (isEmptyAtAll(data)) {
354
+ if (elasticsearchService && elasticsearch_logs_index) {
355
+ elasticsearchService.log(elasticsearch_logs_index, {
356
+ action: 'getStatus',
357
+ method: methodName,
358
+ status: 'error',
359
+ message: `getStatus function Error: ${text}`,
360
+ timestamp: new Date(),
361
+ });
362
+ }
354
363
  logger.error(`getStatus function Error: ${text} `);
355
364
  return {
356
365
  code: codeError,
@@ -390,7 +399,7 @@ const getRedisLogMessage = (functionName, redis, options) => {
390
399
  };
391
400
  };
392
401
  exports.getRedisLogMessage = getRedisLogMessage;
393
- async function executeWithReturn(logger, logMessage, func, ...args) {
402
+ async function executeWithReturn(logger, logMessage, func, elasticsearchService, elasticsearch_logs_index, methodName, ...args) {
394
403
  try {
395
404
  const result = await func(...args);
396
405
  if (isEmptyAtAll(result)) {
@@ -405,17 +414,35 @@ async function executeWithReturn(logger, logMessage, func, ...args) {
405
414
  }
406
415
  catch (error) {
407
416
  logMessage.misc = { ...logMessage.misc, error };
417
+ if (elasticsearchService && elasticsearch_logs_index) {
418
+ elasticsearchService.log(elasticsearch_logs_index, {
419
+ action: 'executeWithReturn',
420
+ method: methodName,
421
+ status: 'error',
422
+ message: logMessage,
423
+ timestamp: new Date(),
424
+ });
425
+ }
408
426
  logger.error(logMessage);
409
427
  return null;
410
428
  }
411
429
  }
412
- async function executeWithoutReturn(logger, logMessage, func, ...args) {
430
+ async function executeWithoutReturn(logger, logMessage, func, elasticsearchService, elasticsearch_logs_index, methodName, ...args) {
413
431
  try {
414
432
  const result = await func(...args);
415
433
  return result;
416
434
  }
417
435
  catch (error) {
418
436
  logMessage.misc = { ...logMessage.misc, error };
437
+ if (elasticsearchService && elasticsearch_logs_index) {
438
+ elasticsearchService.log(elasticsearch_logs_index, {
439
+ action: 'executeWithoutReturn',
440
+ method: methodName,
441
+ status: 'error',
442
+ message: logMessage,
443
+ timestamp: new Date(),
444
+ });
445
+ }
419
446
  logger.error(logMessage);
420
447
  return null;
421
448
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jr-common-micro",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,