@mondart/nestjs-common-module 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.
@@ -1,5 +1,8 @@
1
- export declare function CustomApiResponse(options: {
2
- status: number;
3
- description: string;
4
- responseDto: any;
1
+ export declare function CustomApiResponse({ options, }: {
2
+ options: {
3
+ status: number;
4
+ description: string;
5
+ responseDto: any;
6
+ isArray?: boolean;
7
+ };
5
8
  }): (target: any, key?: string, descriptor?: PropertyDescriptor) => void;
@@ -3,21 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomApiResponse = CustomApiResponse;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
- const success_response_dto_1 = require("../dto/response/success-response.dto");
6
+ const dto_1 = require("../dto");
7
7
  const swagger_2 = require("@nestjs/swagger");
8
- function CustomApiResponse(options) {
8
+ function CustomApiResponse({ options, }) {
9
9
  return function (target, key, descriptor) {
10
+ const dataSchema = options.isArray
11
+ ? {
12
+ type: 'array',
13
+ items: {
14
+ $ref: (0, swagger_1.getSchemaPath)(options.responseDto),
15
+ },
16
+ }
17
+ : {
18
+ $ref: (0, swagger_1.getSchemaPath)(options.responseDto),
19
+ };
10
20
  return (0, common_1.applyDecorators)((0, swagger_2.ApiResponse)({
11
21
  status: options.status,
12
22
  description: options.description,
13
23
  schema: {
14
- $ref: (0, swagger_1.getSchemaPath)(success_response_dto_1.SuccessResponse),
15
24
  type: 'object',
16
- properties: {
17
- data: {
18
- $ref: (0, swagger_1.getSchemaPath)(options.responseDto),
25
+ allOf: [
26
+ { $ref: (0, swagger_1.getSchemaPath)(dto_1.SuccessResponse) },
27
+ {
28
+ properties: {
29
+ data: dataSchema,
30
+ },
19
31
  },
20
- },
32
+ ],
21
33
  },
22
34
  }))(target, key, descriptor);
23
35
  };
@@ -1,5 +1,5 @@
1
1
  export declare enum SharedMessages {
2
- INTERNAL_SERVER_ERROR = "Internal Server Error.",
2
+ INTERNAL_SERVER_ERROR = "Internal Server Error {0}.",
3
3
  NOT_IMPLEMENTED = "This feature has not been implemented yet.",
4
4
  RECURSIVE_CHILD = "Some children IDs are invalid, the parent product can not be used in children, it is recursive.",
5
5
  SUCCESSFUL = "Operation completed successfully.",
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SharedMessages = void 0;
4
4
  var SharedMessages;
5
5
  (function (SharedMessages) {
6
- SharedMessages["INTERNAL_SERVER_ERROR"] = "Internal Server Error.";
6
+ SharedMessages["INTERNAL_SERVER_ERROR"] = "Internal Server Error {0}.";
7
7
  SharedMessages["NOT_IMPLEMENTED"] = "This feature has not been implemented yet.";
8
8
  SharedMessages["RECURSIVE_CHILD"] = "Some children IDs are invalid, the parent product can not be used in children, it is recursive.";
9
9
  SharedMessages["SUCCESSFUL"] = "Operation completed successfully.";
@@ -15,6 +15,7 @@ const config_1 = require("@nestjs/config");
15
15
  const rxjs_1 = require("rxjs");
16
16
  const dto_1 = require("../dto");
17
17
  const enums_1 = require("../enums");
18
+ const helpers_1 = require("../helpers");
18
19
  let GlobalExceptionFilter = class GlobalExceptionFilter {
19
20
  constructor(configService) {
20
21
  this.configService = configService;
@@ -25,8 +26,8 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
25
26
  const type = host?.getType();
26
27
  if (type === 'rpc') {
27
28
  try {
28
- logger.error(exception?.response ?? exception?.message);
29
- return (0, rxjs_1.throwError)(() => exception?.response ?? exception?.message);
29
+ logger.error(exception ?? exception?.message);
30
+ return (0, rxjs_1.throwError)(() => exception ?? exception?.message);
30
31
  }
31
32
  catch (err) {
32
33
  return (0, rxjs_1.throwError)(() => JSON.stringify(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR)));
@@ -34,9 +35,9 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
34
35
  }
35
36
  if (type === 'http') {
36
37
  const response = context.getResponse();
37
- const status = exception?.getStatus();
38
- const result = exception.getResponse();
39
38
  try {
39
+ const status = exception?.getStatus();
40
+ const result = exception.getResponse();
40
41
  if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
41
42
  return response.status(status).json(result);
42
43
  }
@@ -63,7 +64,7 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
63
64
  catch (err) {
64
65
  response
65
66
  .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
+ .json(new dto_1.ErrorResponse(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, exception?.message), common_1.HttpStatus.INTERNAL_SERVER_ERROR));
67
68
  }
68
69
  }
69
70
  }