@mondart/nestjs-common-module 1.0.3 → 1.0.4

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.
Files changed (186) hide show
  1. package/dist/caching/caching.module.js.map +1 -1
  2. package/dist/caching/caching.service.js.map +1 -1
  3. package/dist/caching/index.js.map +1 -1
  4. package/dist/constants/index.js.map +1 -1
  5. package/dist/constants/validation-constraints.const.js.map +1 -1
  6. package/dist/controllers/core-crud.controller.d.ts +4 -4
  7. package/dist/controllers/core-crud.controller.js +6 -6
  8. package/dist/controllers/core-crud.controller.js.map +1 -1
  9. package/dist/controllers/index.js.map +1 -1
  10. package/dist/decorators/entity-order.decorator.js.map +1 -1
  11. package/dist/decorators/index.js.map +1 -1
  12. package/dist/decorators/swagger-api-response.decorator.js.map +1 -1
  13. package/dist/decorators/validations/default/array-max-size.decorator.js.map +1 -1
  14. package/dist/decorators/validations/default/array-min-size.decorator.js.map +1 -1
  15. package/dist/decorators/validations/default/array-not-empty.decorator.js.map +1 -1
  16. package/dist/decorators/validations/default/index.js.map +1 -1
  17. package/dist/decorators/validations/default/is-array.decorator.js.map +1 -1
  18. package/dist/decorators/validations/default/is-boolean.decorator.js.map +1 -1
  19. package/dist/decorators/validations/default/is-date.decorator.js.map +1 -1
  20. package/dist/decorators/validations/default/is-enum.decorator.js.map +1 -1
  21. package/dist/decorators/validations/default/is-int.decorator.js.map +1 -1
  22. package/dist/decorators/validations/default/is-not-empty-object.decorator.js.map +1 -1
  23. package/dist/decorators/validations/default/is-not-empty.decorator.js.map +1 -1
  24. package/dist/decorators/validations/default/is-number-string.decorator.js.map +1 -1
  25. package/dist/decorators/validations/default/is-object.decorator.js.map +1 -1
  26. package/dist/decorators/validations/default/is-positive.decorator.js.map +1 -1
  27. package/dist/decorators/validations/default/is-string.decorator.js.map +1 -1
  28. package/dist/decorators/validations/default/is-uuid.decorator.js.map +1 -1
  29. package/dist/decorators/validations/default/matches.decorator.js.map +1 -1
  30. package/dist/decorators/validations/default/max-length.decorator.js.map +1 -1
  31. package/dist/decorators/validations/default/max.decorator.js.map +1 -1
  32. package/dist/decorators/validations/default/min-length.decorator.js.map +1 -1
  33. package/dist/decorators/validations/default/min.decorator.js.map +1 -1
  34. package/dist/decorators/validations/index.js.map +1 -1
  35. package/dist/decorators/validations/is-id.decorator.js.map +1 -1
  36. package/dist/decorators/validations/is-not-empty-string.decorator.js.map +1 -1
  37. package/dist/dto/index.js.map +1 -1
  38. package/dist/dto/request/base-request.dto.js.map +1 -1
  39. package/dist/dto/request/event.dto.js.map +1 -1
  40. package/dist/dto/request/id.dto.js.map +1 -1
  41. package/dist/dto/request/ids.dto.js.map +1 -1
  42. package/dist/dto/request/index.js.map +1 -1
  43. package/dist/dto/response/base-response-with-action-dates.dto.js.map +1 -1
  44. package/dist/dto/response/base-response.dto.js.map +1 -1
  45. package/dist/dto/response/error-response.dto.js.map +1 -1
  46. package/dist/dto/response/index.js.map +1 -1
  47. package/dist/dto/response/kafka-success-response.dto.js.map +1 -1
  48. package/dist/dto/response/success-response.dto.js.map +1 -1
  49. package/dist/dto/response/validation.dto.js.map +1 -1
  50. package/dist/entities/action-dates.entity.js.map +1 -1
  51. package/dist/entities/base.entity.js.map +1 -1
  52. package/dist/entities/index.js.map +1 -1
  53. package/dist/entities/parent.entity.js.map +1 -1
  54. package/dist/enums/environments.enum.js.map +1 -1
  55. package/dist/enums/index.js.map +1 -1
  56. package/dist/enums/shared-messages.enum.js.map +1 -1
  57. package/dist/filters/http-exception.filter.js.map +1 -1
  58. package/dist/filters/index.js.map +1 -1
  59. package/dist/filters/rpc-exception.filter.js.map +1 -1
  60. package/dist/helper/get-env.helper.js.map +1 -1
  61. package/dist/helper/get-env.js.map +1 -1
  62. package/dist/helper/index.js.map +1 -1
  63. package/dist/helper/message-formatter.helper.js.map +1 -1
  64. package/dist/helper/multi-inheritance.helper.js.map +1 -1
  65. package/dist/helper/multi-inheritance.util.js.map +1 -1
  66. package/dist/index.js.map +1 -1
  67. package/dist/interface/core-crud-service.option.js.map +1 -1
  68. package/dist/interface/custom-validation-arguments.interface.js.map +1 -1
  69. package/dist/interface/index.js.map +1 -1
  70. package/dist/interface/kafka-success-response.interfase.js.map +1 -1
  71. package/dist/interface/pagination-query.js.map +1 -1
  72. package/dist/lib/index.js.map +1 -1
  73. package/dist/lib/kafka/constant/consumer.const.js.map +1 -1
  74. package/dist/lib/kafka/constant/kafka.const.js.map +1 -1
  75. package/dist/lib/kafka/index.js.map +1 -1
  76. package/dist/lib/kafka/kafka-admin.service.js.map +1 -1
  77. package/dist/lib/kafka/kafka-consumer.service.js.map +1 -1
  78. package/dist/lib/kafka/kafka-instance.const.js.map +1 -1
  79. package/dist/lib/kafka/kafka-logger.js.map +1 -1
  80. package/dist/lib/kafka/kafka-producer.service.js.map +1 -1
  81. package/dist/lib/kafka/kafka.interface.js.map +1 -1
  82. package/dist/lib/kafka/kafka.module.js.map +1 -1
  83. package/dist/lib/kafka/kafka.provider.js.map +1 -1
  84. package/dist/lib/kafka/kafka.service.js.map +1 -1
  85. package/dist/services/core-crud.service.js.map +1 -1
  86. package/dist/services/index.js.map +1 -1
  87. package/dist/strategy/index.js.map +1 -1
  88. package/dist/strategy/type-orm-naming.strategy.js.map +1 -1
  89. package/dist/tsconfig.tsbuildinfo +1 -1
  90. package/dist/validators/does-exist.validator.js.map +1 -1
  91. package/dist/validators/env.validator.js.map +1 -1
  92. package/dist/validators/index.js.map +1 -1
  93. package/dist/validators/is-unique.validator.js.map +1 -1
  94. package/dist/validators/validation-options.js.map +1 -1
  95. package/package.json +2 -2
  96. package/common/caching/caching.module.ts +0 -28
  97. package/common/caching/caching.service.ts +0 -34
  98. package/common/caching/index.ts +0 -2
  99. package/common/constants/index.ts +0 -1
  100. package/common/constants/validation-constraints.const.ts +0 -14
  101. package/common/controllers/core-crud.controller.ts +0 -106
  102. package/common/controllers/index.ts +0 -1
  103. package/common/decorators/entity-order.decorator.ts +0 -19
  104. package/common/decorators/index.ts +0 -2
  105. package/common/decorators/swagger-api-response.decorator.ts +0 -30
  106. package/common/decorators/validations/default/array-max-size.decorator.ts +0 -9
  107. package/common/decorators/validations/default/array-min-size.decorator.ts +0 -9
  108. package/common/decorators/validations/default/array-not-empty.decorator.ts +0 -7
  109. package/common/decorators/validations/default/index.ts +0 -20
  110. package/common/decorators/validations/default/is-array.decorator.ts +0 -7
  111. package/common/decorators/validations/default/is-boolean.decorator.ts +0 -10
  112. package/common/decorators/validations/default/is-date.decorator.ts +0 -10
  113. package/common/decorators/validations/default/is-enum.decorator.ts +0 -9
  114. package/common/decorators/validations/default/is-int.decorator.ts +0 -10
  115. package/common/decorators/validations/default/is-not-empty-object.decorator.ts +0 -15
  116. package/common/decorators/validations/default/is-not-empty.decorator.ts +0 -7
  117. package/common/decorators/validations/default/is-number-string.decorator.ts +0 -12
  118. package/common/decorators/validations/default/is-object.decorator.ts +0 -7
  119. package/common/decorators/validations/default/is-positive.decorator.ts +0 -10
  120. package/common/decorators/validations/default/is-string.decorator.ts +0 -8
  121. package/common/decorators/validations/default/is-uuid.decorator.ts +0 -7
  122. package/common/decorators/validations/default/matches.decorator.ts +0 -13
  123. package/common/decorators/validations/default/max-length.decorator.ts +0 -9
  124. package/common/decorators/validations/default/max.decorator.ts +0 -13
  125. package/common/decorators/validations/default/min-length.decorator.ts +0 -9
  126. package/common/decorators/validations/default/min.decorator.ts +0 -13
  127. package/common/decorators/validations/index.ts +0 -3
  128. package/common/decorators/validations/is-id.decorator.ts +0 -20
  129. package/common/decorators/validations/is-not-empty-string.decorator.ts +0 -14
  130. package/common/dto/index.ts +0 -2
  131. package/common/dto/request/base-request.dto.ts +0 -11
  132. package/common/dto/request/event.dto.ts +0 -25
  133. package/common/dto/request/id.dto.ts +0 -10
  134. package/common/dto/request/ids.dto.ts +0 -13
  135. package/common/dto/request/index.ts +0 -4
  136. package/common/dto/response/base-response-with-action-dates.dto.ts +0 -19
  137. package/common/dto/response/base-response.dto.ts +0 -10
  138. package/common/dto/response/error-response.dto.ts +0 -22
  139. package/common/dto/response/index.ts +0 -5
  140. package/common/dto/response/kafka-success-response.dto.ts +0 -56
  141. package/common/dto/response/success-response.dto.ts +0 -32
  142. package/common/dto/response/validation.dto.ts +0 -80
  143. package/common/entities/action-dates.entity.ts +0 -30
  144. package/common/entities/base.entity.ts +0 -7
  145. package/common/entities/index.ts +0 -2
  146. package/common/entities/parent.entity.ts +0 -35
  147. package/common/enums/environments.enum.ts +0 -6
  148. package/common/enums/index.ts +0 -2
  149. package/common/enums/shared-messages.enum.ts +0 -40
  150. package/common/filters/http-exception.filter.ts +0 -74
  151. package/common/filters/index.ts +0 -1
  152. package/common/filters/rpc-exception.filter.ts +0 -40
  153. package/common/helper/get-env.helper.ts +0 -3
  154. package/common/helper/get-env.ts +0 -3
  155. package/common/helper/index.ts +0 -2
  156. package/common/helper/message-formatter.helper.ts +0 -30
  157. package/common/helper/multi-inheritance.helper.ts +0 -12
  158. package/common/helper/multi-inheritance.util.ts +0 -12
  159. package/common/index.ts +0 -14
  160. package/common/interface/core-crud-service.option.ts +0 -8
  161. package/common/interface/custom-validation-arguments.interface.ts +0 -20
  162. package/common/interface/index.ts +0 -2
  163. package/common/interface/kafka-success-response.interfase.ts +0 -9
  164. package/common/interface/pagination-query.ts +0 -39
  165. package/common/lib/index.ts +0 -1
  166. package/common/lib/kafka/constant/consumer.const.ts +0 -13
  167. package/common/lib/kafka/constant/kafka.const.ts +0 -9
  168. package/common/lib/kafka/index.ts +0 -5
  169. package/common/lib/kafka/kafka-admin.service.ts +0 -51
  170. package/common/lib/kafka/kafka-consumer.service.ts +0 -59
  171. package/common/lib/kafka/kafka-instance.const.ts +0 -9
  172. package/common/lib/kafka/kafka-logger.ts +0 -25
  173. package/common/lib/kafka/kafka-producer.service.ts +0 -97
  174. package/common/lib/kafka/kafka.interface.ts +0 -22
  175. package/common/lib/kafka/kafka.module.ts +0 -80
  176. package/common/lib/kafka/kafka.provider.ts +0 -10
  177. package/common/lib/kafka/kafka.service.ts +0 -224
  178. package/common/services/core-crud.service.ts +0 -457
  179. package/common/services/index.ts +0 -1
  180. package/common/strategy/index.ts +0 -1
  181. package/common/strategy/type-orm-naming.strategy.ts +0 -17
  182. package/common/validators/does-exist.validator.ts +0 -42
  183. package/common/validators/env.validator.ts +0 -28
  184. package/common/validators/index.ts +0 -4
  185. package/common/validators/is-unique.validator.ts +0 -70
  186. package/common/validators/validation-options.ts +0 -38
@@ -1,10 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
- import { Type } from 'class-transformer';
3
- import { IsId } from '../../decorators/validations/is-id.decorator';
4
-
5
- export class IdDto {
6
- @ApiProperty({ default: 1 })
7
- @Type(() => Number)
8
- @IsId({ optional: false })
9
- id: number;
10
- }
@@ -1,13 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
- import { Transform } from 'class-transformer';
3
- import { IsId } from '../../decorators/validations/is-id.decorator';
4
-
5
- export class IdsDto {
6
- @ApiProperty({ default: [1], isArray: true })
7
- @Transform((o) => {
8
- const ids = o.value.split(',');
9
- return ids.map((value: string) => Number(value));
10
- })
11
- @IsId({ optional: false, each: true })
12
- ids: number[];
13
- }
@@ -1,4 +0,0 @@
1
- export * from './base-request.dto';
2
- export * from './event.dto';
3
- export * from './id.dto';
4
- export * from './ids.dto';
@@ -1,19 +0,0 @@
1
- import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2
- import { BaseResponse } from './base-response.dto';
3
-
4
- export class BaseResponseWithActionDates extends BaseResponse {
5
- @ApiProperty({ type: Date })
6
- public createdAt: Date;
7
- @ApiProperty({ type: Date })
8
- public updatedAt: Date;
9
- @ApiPropertyOptional({ type: Date, default: null })
10
- public deletedAt?: Date;
11
-
12
- constructor(init: Partial<BaseResponseWithActionDates>) {
13
- super(init);
14
-
15
- this.createdAt = init?.createdAt;
16
- this.updatedAt = init?.updatedAt;
17
- this.deletedAt = init?.deletedAt;
18
- }
19
- }
@@ -1,10 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
-
3
- export class BaseResponse {
4
- @ApiProperty({ example: 1 })
5
- public id?: number;
6
-
7
- constructor(init?: Partial<BaseResponse>) {
8
- this.id = init?.id;
9
- }
10
- }
@@ -1,22 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
-
3
- export class BaseErrorResponse {
4
- @ApiProperty({ type: String })
5
- message: string;
6
-
7
- @ApiProperty({ type: Number })
8
- statusCode: number;
9
-
10
- @ApiProperty()
11
- details: Record<string, any>;
12
- }
13
-
14
- export class ErrorResponse extends BaseErrorResponse {
15
- constructor(message: string, statusCode: number, details: any = {}) {
16
- super();
17
-
18
- this.message = message;
19
- this.statusCode = statusCode;
20
- this.details = details;
21
- }
22
- }
@@ -1,5 +0,0 @@
1
- export * from './base-response-with-action-dates.dto';
2
- export * from './base-response.dto';
3
- export * from './error-response.dto';
4
- export * from './success-response.dto';
5
- export * from './validation.dto';
@@ -1,56 +0,0 @@
1
- import { IsNumber, IsOptional, IsString } from 'class-validator';
2
- import { KafkaSuccessResponseInterface } from '../../interface/kafka-success-response.interfase';
3
-
4
- export class BaseEventDto<type> {
5
- @IsString()
6
- @IsOptional()
7
- topic?: string;
8
-
9
- @IsString()
10
- event_source: string;
11
-
12
- @IsString()
13
- @IsOptional()
14
- model?: string;
15
-
16
- @IsString()
17
- @IsOptional()
18
- event_key?: string;
19
-
20
- @IsOptional()
21
- data?: type;
22
-
23
- @IsNumber()
24
- @IsOptional()
25
- partition?: number;
26
-
27
- @IsNumber()
28
- @IsOptional()
29
- status?: number;
30
- }
31
-
32
- export class KafkaSuccessResponse<type> extends BaseEventDto<type> {
33
- constructor({
34
- data,
35
- event_source,
36
- topic,
37
- model,
38
- event_key,
39
- partition,
40
- status,
41
- }: KafkaSuccessResponseInterface<type>) {
42
- super();
43
-
44
- this.data = data;
45
- this.topic = topic;
46
- this.event_source = event_source;
47
- this.model = model;
48
- this.event_key = event_key;
49
- this.partition = partition;
50
- this.status = status;
51
- }
52
-
53
- public stringify() {
54
- return JSON.stringify(this);
55
- }
56
- }
@@ -1,32 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
- import { SharedMessages } from '../../enums/shared-messages.enum';
3
-
4
- export class BaseSuccessResponse<type> {
5
- @ApiProperty({ type: Object })
6
- data: type;
7
-
8
- @ApiProperty({ type: Object })
9
- metadata: object;
10
-
11
- @ApiProperty({ type: String, default: SharedMessages.SUCCESSFUL })
12
- message: string;
13
-
14
- @ApiProperty({ type: Number, default: 200 })
15
- statusCode: number;
16
- }
17
-
18
- export class SuccessResponse<type> extends BaseSuccessResponse<type> {
19
- constructor(
20
- data: type,
21
- message: string = null,
22
- statusCode = 200,
23
- metadata = null,
24
- ) {
25
- super();
26
-
27
- this.data = data;
28
- this.message = message;
29
- this.statusCode = statusCode;
30
- this.metadata = metadata;
31
- }
32
- }
@@ -1,80 +0,0 @@
1
- import { HttpStatus, ValidationError } from '@nestjs/common';
2
- import { ApiProperty } from '@nestjs/swagger';
3
-
4
- export class validationErrorMsg {
5
- @ApiProperty({ type: String })
6
- field: string;
7
-
8
- @ApiProperty({ type: String })
9
- message: string;
10
- }
11
-
12
- class ValidationMsg {
13
- @ApiProperty({ type: String })
14
- entity: string;
15
-
16
- @ApiProperty({
17
- type: validationErrorMsg,
18
- isArray: true,
19
- })
20
- errors: Array<validationErrorMsg>;
21
- }
22
-
23
- export class ValidationErrorResponseType {
24
- @ApiProperty({ type: String })
25
- message: string;
26
-
27
- @ApiProperty({ type: String })
28
- statusCode: string;
29
-
30
- @ApiProperty({ type: ValidationMsg })
31
- validationMsg: ValidationMsg;
32
- }
33
-
34
- export class ValidationErrorResponseDto {
35
- public message: string;
36
- public statusCode: string;
37
- public validationMsg: object;
38
-
39
- constructor(
40
- message: string,
41
- error: {
42
- validationErrors?: Array<ValidationError>;
43
- errors?: validationErrorMsg[];
44
- },
45
- ) {
46
- let validation =
47
- error.validationErrors &&
48
- error.validationErrors.map((error) => {
49
- error = { ...error, ...this.formatValidationError(error) };
50
-
51
- const field = error.property;
52
-
53
- const message = Object.values(error.constraints)[0];
54
-
55
- return {
56
- field,
57
- message,
58
- };
59
- });
60
-
61
- validation = validation || error.errors;
62
-
63
- this.message = message;
64
- this.statusCode = String(HttpStatus.BAD_REQUEST);
65
- this.validationMsg = {
66
- errors: validation,
67
- };
68
- }
69
-
70
- private formatValidationError(err: ValidationError) {
71
- if (err.children.length === 0)
72
- return {
73
- property: err.property,
74
- constraints: err.constraints,
75
- children: err.children,
76
- };
77
-
78
- return this.formatValidationError(err.children[0]);
79
- }
80
- }
@@ -1,30 +0,0 @@
1
- import {
2
- CreateDateColumn,
3
- UpdateDateColumn,
4
- DeleteDateColumn,
5
- Column,
6
- BaseEntity,
7
- } from 'typeorm';
8
- import { Order } from '../decorators/entity-order.decorator';
9
-
10
- export class ActionDatesEntity extends BaseEntity {
11
- @Order(9999)
12
- @CreateDateColumn()
13
- createdAt: Date;
14
-
15
- @Order(9999)
16
- @UpdateDateColumn()
17
- updatedAt: Date;
18
-
19
- @Order(9999)
20
- @DeleteDateColumn()
21
- deletedAt: Date;
22
-
23
- @Order(9999)
24
- @Column({ nullable: true })
25
- createdBy?: string;
26
-
27
- @Order(9999)
28
- @Column({ nullable: true })
29
- updatedBy?: string;
30
- }
@@ -1,7 +0,0 @@
1
- import { Column } from 'typeorm';
2
- import { ActionDatesEntity } from './action-dates.entity';
3
-
4
- export class ParentEntity extends ActionDatesEntity {
5
- @Column({ default: true })
6
- isActive: boolean;
7
- }
@@ -1,2 +0,0 @@
1
- export * from './action-dates.entity';
2
- export * from './base.entity';
@@ -1,35 +0,0 @@
1
- import {
2
- BaseEntity,
3
- Column,
4
- DataSource,
5
- PrimaryGeneratedColumn,
6
- } from 'typeorm';
7
- import { ActionDatesEntity } from './action-dates.entity';
8
- import { getOrder, Order } from '../decorators/entity-order.decorator';
9
-
10
- export class ParentEntity extends ActionDatesEntity {
11
- @Order(-1)
12
- @PrimaryGeneratedColumn()
13
- id: number;
14
-
15
- @Order(9998)
16
- @Column({ default: true })
17
- isActive: boolean;
18
-
19
- @Order(9999)
20
- @Column({ type: 'json', nullable: true })
21
- metadata?: any;
22
-
23
- static useDataSource(dataSource: DataSource) {
24
- BaseEntity.useDataSource.call(this, dataSource);
25
- const meta = dataSource.entityMetadatasMap.get(this);
26
- if (meta != null) {
27
- // reorder columns here
28
- meta.columns = [...meta.columns].sort((x, y) => {
29
- const orderX = getOrder((x.target as any).prototype, x.propertyName);
30
- const orderY = getOrder((y.target as any).prototype, y.propertyName);
31
- return orderX - orderY;
32
- });
33
- }
34
- }
35
- }
@@ -1,6 +0,0 @@
1
- export enum Environments {
2
- PRODUCTION = 'production',
3
- STAGE = 'stage',
4
- TEST = 'test',
5
- DEVELOP = 'develop',
6
- }
@@ -1,2 +0,0 @@
1
- export * from './environments.enum';
2
- export * from './environments.enum';
@@ -1,40 +0,0 @@
1
- export enum SharedMessages {
2
- // Generic errors
3
- INTERNAL_SERVER_ERROR = 'Internal Server Error.',
4
- NOT_IMPLEMENTED = 'This feature has not been implemented yet.',
5
- RECURSIVE_CHILD = 'Some children IDs are invalid, the parent product can not be used in children, it is recursive.',
6
- SUCCESSFUL = 'Operation completed successfully.',
7
- IS_UNiQUE = 'Field must be unique.',
8
-
9
- // Create (POST) specific errors
10
- CREATE_FAILED = 'Failed to create: {0}.',
11
- CREATE_DENIED = 'Permission denied to create: {0}.',
12
-
13
- // Read (GET) specific errors
14
- FETCH_FAILED = 'Failed to fetch: {0}.',
15
- RESOURCE_NOT_FOUND = 'The requested {0} was not found.',
16
- DUPLICATED_SKU = 'The SKU is reserved.',
17
- DUPLICATED_CODE = 'The Code is reserved.',
18
- INVALID_COMPOSITE_SUB_ITEMS = 'Composite sub items are invalid.',
19
- INVALID_GROUPED_SUB_ITEMS = 'Sub items are invalid.',
20
-
21
- // Update (PUT/PATCH) specific errors
22
- UPDATE_FAILED = 'Failed to update: {0}.',
23
- UPDATE_DENIED = 'Permission denied to update: {0}.',
24
-
25
- // Upsert (PUT/PATCH) specific errors
26
- UPSERT_FAILED = 'Failed to upsert: {0}.',
27
- UPSERT_DENIED = 'Permission denied to upsert: {0}.',
28
-
29
- // Delete (DELETE) specific errors
30
- DELETE_FAILED = 'Failed to delete: {0}.',
31
- DELETE_DENIED = 'Permission denied to delete: {0}.',
32
-
33
- // Validation errors
34
- SORT_VALIDATION_FAILED = 'Sort parameter validation failed {0}.',
35
- PARAMETER_VALIDATION_FAILED = 'Parameter validation failed {0}.',
36
-
37
- // Authentication and Authorization errors
38
- UNAUTHORIZED = 'Authorization is required to access this {0}.',
39
- FORBIDDEN = 'Access to this {0} is forbidden.',
40
- }
@@ -1,74 +0,0 @@
1
- import {
2
- ArgumentsHost,
3
- Catch,
4
- ExceptionFilter,
5
- HttpException,
6
- HttpStatus,
7
- Logger,
8
- } from '@nestjs/common';
9
- import { Response } from 'express';
10
- import { ErrorResponse } from '../dto';
11
- import { ConfigService } from '@nestjs/config';
12
- import { SharedMessages } from '../enums/shared-messages.enum';
13
- import { KafkaContext } from '@nestjs/microservices';
14
-
15
- @Catch(HttpException)
16
- export class HttpExceptionFilter implements ExceptionFilter {
17
- constructor(private readonly configService: ConfigService) {}
18
- catch(exception: HttpException, host: ArgumentsHost) {
19
- const context = host.switchToHttp();
20
- const response = context.getResponse<Response>();
21
- const status = exception.getStatus();
22
- const result = exception.getResponse() as {
23
- message: string | string[];
24
- error: string | string[];
25
- details: any;
26
- };
27
- const logger = new Logger('OrderKafkaController', { timestamp: true });
28
-
29
- if (response instanceof KafkaContext) {
30
- logger.error(result);
31
-
32
- // TODO: add sentry for manage kafka exceptions
33
- }
34
- try {
35
- if (status === HttpStatus.UNPROCESSABLE_ENTITY) {
36
- return response.status(status).json(result);
37
- } else if (status === HttpStatus.BAD_REQUEST) {
38
- // if (result instanceof SharedMessages) {
39
- //
40
- // }
41
- return response
42
- .status(status)
43
- .json(
44
- new ErrorResponse(
45
- String(result?.error),
46
- status,
47
- typeof result?.message === 'string'
48
- ? result?.message
49
- : result?.message[0],
50
- ),
51
- );
52
- } else {
53
- let message: string;
54
-
55
- if (typeof result.message === 'string') {
56
- message = result?.message;
57
- } else {
58
- message = result?.message[0];
59
- }
60
-
61
- return response.status(status).json(new ErrorResponse(message, status));
62
- }
63
- } catch (err) {
64
- response
65
- .status(HttpStatus.INTERNAL_SERVER_ERROR)
66
- .json(
67
- new ErrorResponse(
68
- SharedMessages.INTERNAL_SERVER_ERROR,
69
- HttpStatus.INTERNAL_SERVER_ERROR,
70
- ),
71
- );
72
- }
73
- }
74
- }
@@ -1 +0,0 @@
1
- export * from './http-exception.filter';
@@ -1,40 +0,0 @@
1
- import { Catch, ArgumentsHost } from '@nestjs/common';
2
- import { BaseRpcExceptionFilter, RpcException } from '@nestjs/microservices';
3
-
4
- @Catch(RpcException)
5
- export class KafkaExceptionFilter extends BaseRpcExceptionFilter {
6
- catch(exception: any, host: ArgumentsHost) {
7
- return super.catch(exception, host);
8
- }
9
- }
10
-
11
- // @Catch(RpcException)
12
- // export class CustomRpcExceptionFilter
13
- // implements RpcExceptionFilter<RpcException>
14
- // {
15
- // catch(exception: RpcException, host: ArgumentsHost) {
16
- // const ctx = host.switchToRpc();
17
- // const response = ctx.getContext();
18
- //
19
- // const status =
20
- // exception instanceof HttpException
21
- // ? exception.getStatus()
22
- // : HttpStatus.INTERNAL_SERVER_ERROR;
23
- //
24
- // const message = exception.message || 'Internal server error';
25
- //
26
- // return response.send({
27
- // statusCode: status,
28
- // message: message,
29
- // });
30
- // }
31
- // // catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
32
- // // return throwError(() =>
33
- // // new KafkaSuccessResponse<any>({
34
- // // data: exception.getError(),
35
- // // event_source: 'product',
36
- // // status: 400,
37
- // // }).stringify(),
38
- // // );
39
- // // }
40
- // }
@@ -1,3 +0,0 @@
1
- export function env(key, defaultValue: any = null) {
2
- return process?.env?.[key] ?? defaultValue;
3
- }
@@ -1,3 +0,0 @@
1
- export function env(key, defaultValue: any = null) {
2
- return process?.env?.[key] ?? defaultValue;
3
- }
@@ -1,2 +0,0 @@
1
- export * from './get-env';
2
- export * from './multi-inheritance.util';
@@ -1,30 +0,0 @@
1
- export class MessageFormatter {
2
- /**
3
- * Function to replace a message from the SharedMessages enum with custom arguments.
4
- * @param message The message of the SharedMessages enum.
5
- * @param args Custom arguments to replace placeholders in the message.
6
- * @returns The formatted message.
7
- */
8
- static replace(message: string, ...args: any[]): string {
9
- // Check if the message exists in the enum
10
- if (!message) {
11
- throw new Error(`Message with key ${message} does not exist.`);
12
- }
13
-
14
- // Replace placeholders in the message with provided arguments
15
- if (args.length !== 0) {
16
- args.forEach((arg, index) => {
17
- const placeholder = `{${index}}`;
18
- if (arg !== undefined && arg !== null) {
19
- message = message.replace(placeholder, String(arg));
20
- } else {
21
- message = message.replace(placeholder, '');
22
- }
23
- });
24
- } else {
25
- message = message.replace(' {0} ', ' ');
26
- }
27
-
28
- return message;
29
- }
30
- }
@@ -1,12 +0,0 @@
1
- export const multiInheritance = (baseClass: any, extendedClasses: any[]) => {
2
- extendedClasses.forEach((extendedClass) => {
3
- Object.getOwnPropertyNames(extendedClass.prototype).forEach((name) => {
4
- Object.defineProperty(
5
- baseClass.prototype,
6
- name,
7
- Object.getOwnPropertyDescriptor(extendedClass.prototype, name) ||
8
- Object.create(null),
9
- );
10
- });
11
- });
12
- };
@@ -1,12 +0,0 @@
1
- export const multiInheritance = (baseClass: any, extendedClasses: any[]) => {
2
- extendedClasses.forEach((extendedClass) => {
3
- Object.getOwnPropertyNames(extendedClass.prototype).forEach((name) => {
4
- Object.defineProperty(
5
- baseClass.prototype,
6
- name,
7
- Object.getOwnPropertyDescriptor(extendedClass.prototype, name) ||
8
- Object.create(null),
9
- );
10
- });
11
- });
12
- };
package/common/index.ts DELETED
@@ -1,14 +0,0 @@
1
- export * as caching from './caching';
2
- export * as constants from './constants';
3
- export * as controllers from './controllers';
4
- export * as decorators from './decorators';
5
- export * as dto from './dto';
6
- export * as entities from './entities';
7
- export * as enums from './enums';
8
- export * as filters from './filters';
9
- export * as helper from './helper';
10
- export * as interfaces from './interface';
11
- export * as lib from './lib';
12
- export * as services from './services';
13
- export * as strategy from './strategy';
14
- export * as validators from './validators';
@@ -1,8 +0,0 @@
1
- import { EntityManager } from 'typeorm';
2
- import { FindOptionsRelations } from 'typeorm/find-options/FindOptionsRelations';
3
-
4
- export class CoreCrudServiceOption<T> {
5
- entityManager?: EntityManager;
6
- relations?: FindOptionsRelations<T>;
7
- existsCheck?: boolean = true;
8
- }
@@ -1,20 +0,0 @@
1
- import { ValidationArguments } from 'class-validator/types/validation/ValidationArguments';
2
- import { ValidatorConstraintInterface } from 'class-validator/types/validation/ValidatorConstraintInterface';
3
-
4
- export interface CustomValidationArguments extends ValidationArguments {
5
- constraints: CustomConstraintsInterface[];
6
- }
7
-
8
- export interface CustomConstraintsInterface {
9
- repository: string;
10
- pathToProperty?: string;
11
- whereQuery?: object;
12
- stringPropertyQuery?: string[];
13
- }
14
- export interface CustomValidatorConstraintInterface
15
- extends ValidatorConstraintInterface {
16
- validate(
17
- value: any,
18
- validationArguments?: CustomValidationArguments,
19
- ): Promise<boolean> | boolean;
20
- }
@@ -1,2 +0,0 @@
1
- export * from './core-crud-service.option';
2
- export * from './core-crud-service.option';
@@ -1,9 +0,0 @@
1
- export interface KafkaSuccessResponseInterface<type> {
2
- data: type;
3
- event_source: string;
4
- topic?: string;
5
- model?: string;
6
- event_key?: string;
7
- partition?: number;
8
- status?: number;
9
- }