@mondart/nestjs-common-module 1.1.23 → 1.1.25

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.
@@ -1,8 +1,8 @@
1
- import { ArgumentsHost, ExceptionFilter, HttpException } from '@nestjs/common';
1
+ import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
2
  import { Response } from 'express';
3
3
  import { ConfigService } from '@nestjs/config';
4
4
  export declare class GlobalExceptionFilter implements ExceptionFilter {
5
5
  private readonly configService;
6
6
  constructor(configService: ConfigService);
7
- catch(exception: HttpException, host: ArgumentsHost): Response<any, Record<string, any>> | import("rxjs").Observable<never>;
7
+ catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<never> | Response<any, Record<string, any>>;
8
8
  }
@@ -11,51 +11,60 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GlobalExceptionFilter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
- const dto_1 = require("../dto");
15
14
  const config_1 = require("@nestjs/config");
16
- const enums_1 = require("../enums");
17
- const microservices_1 = require("@nestjs/microservices");
18
15
  const rxjs_1 = require("rxjs");
16
+ const dto_1 = require("../dto");
17
+ const enums_1 = require("../enums");
19
18
  let GlobalExceptionFilter = class GlobalExceptionFilter {
20
19
  constructor(configService) {
21
20
  this.configService = configService;
22
21
  }
23
22
  catch(exception, host) {
24
23
  const context = host.switchToHttp();
25
- const response = context.getResponse();
26
- const status = exception.getStatus();
27
- const result = exception.getResponse();
28
- const logger = new common_1.Logger('OrderKafkaController', { timestamp: true });
29
- try {
30
- if (exception instanceof microservices_1.RpcException) {
31
- logger.error(result);
32
- return (0, rxjs_1.throwError)(() => exception);
33
- }
34
- else if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
35
- return response.status(status).json(result);
24
+ const logger = new common_1.Logger('GlobalExceptionFilter', { timestamp: true });
25
+ const type = host?.getType();
26
+ if (type === 'rpc') {
27
+ try {
28
+ logger.error(exception?.response ?? exception?.message);
29
+ return (0, rxjs_1.throwError)(() => exception?.response ?? exception?.message);
36
30
  }
37
- else if (status === common_1.HttpStatus.BAD_REQUEST) {
38
- return response
39
- .status(status)
40
- .json(new dto_1.ErrorResponse(String(result?.error), status, typeof result?.message === 'string'
41
- ? result?.message
42
- : result?.message[0]));
31
+ catch (err) {
32
+ return (0, rxjs_1.throwError)(() => JSON.stringify(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR)));
43
33
  }
44
- else {
45
- let message;
46
- if (typeof result.message === 'string') {
47
- message = result?.message;
34
+ }
35
+ if (type === 'http') {
36
+ const response = context.getResponse();
37
+ const status = exception?.getStatus();
38
+ const result = exception.getResponse();
39
+ try {
40
+ if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
41
+ return response.status(status).json(result);
42
+ }
43
+ else if (status === common_1.HttpStatus.BAD_REQUEST) {
44
+ return response
45
+ .status(status)
46
+ .json(new dto_1.ErrorResponse(String(result?.error), status, typeof result?.message === 'string'
47
+ ? result?.message
48
+ : result?.message[0]));
48
49
  }
49
50
  else {
50
- message = result?.message[0];
51
+ let message;
52
+ if (typeof result.message === 'string') {
53
+ message = result?.message;
54
+ }
55
+ else {
56
+ message = result?.message[0];
57
+ }
58
+ return response
59
+ .status(status)
60
+ .json(new dto_1.ErrorResponse(message, status));
51
61
  }
52
- return response.status(status).json(new dto_1.ErrorResponse(message, status));
53
62
  }
54
- }
55
- catch (err) {
56
- response
57
- .status(common_1.HttpStatus.INTERNAL_SERVER_ERROR)
58
- .json(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR));
63
+ catch (err) {
64
+ response
65
+ .status(common_1.HttpStatus.INTERNAL_SERVER_ERROR)
66
+ .json(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR));
67
+ }
59
68
  }
60
69
  }
61
70
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoreCrudService = void 0;
4
+ const typeorm_1 = require("typeorm");
4
5
  const common_1 = require("@nestjs/common");
5
6
  const nestjs_paginate_1 = require("nestjs-paginate");
6
7
  const enums_1 = require("../enums");
@@ -235,11 +236,8 @@ class CoreCrudService {
235
236
  return { id };
236
237
  });
237
238
  }
238
- else if (this.isArrayOfObjectId(dtoObject[item])) {
239
- relatedItem = dtoObject[item];
240
- }
241
239
  else {
242
- throw new common_1.BadRequestException(`property: ${item} must be an array of number or array of objectIds`);
240
+ relatedItem = dtoObject[item];
243
241
  }
244
242
  dtoObject[item] = relatedItem;
245
243
  });
@@ -267,7 +265,8 @@ class CoreCrudService {
267
265
  }
268
266
  else if (value !== null &&
269
267
  typeof value === 'object' &&
270
- !Array.isArray(value)) {
268
+ !Array.isArray(value) &&
269
+ !typeorm_1.InstanceChecker.isFindOperator(value)) {
271
270
  const validatedObject = this.whereQueryTransformer(value);
272
271
  if (validatedObject !== undefined) {
273
272
  newQuery[key] = validatedObject;