@nest-omni/core 1.0.3 → 1.0.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.
Files changed (265) hide show
  1. package/package.json +1 -4
  2. package/src/boilerplate.polyfill.d.ts +39 -0
  3. package/src/boilerplate.polyfill.js +78 -0
  4. package/src/boilerplate.polyfill.ts +202 -0
  5. package/src/common/abstract-client.service.d.ts +20 -0
  6. package/src/common/abstract-client.service.js +39 -0
  7. package/src/common/abstract-client.service.ts +56 -0
  8. package/src/common/abstract.entity.d.ts +24 -0
  9. package/src/common/abstract.entity.js +152 -0
  10. package/src/common/abstract.entity.ts +73 -0
  11. package/src/common/dto/abstract.dto.d.ts +13 -0
  12. package/src/common/dto/abstract.dto.js +96 -0
  13. package/src/common/dto/abstract.dto.ts +64 -0
  14. package/src/common/dto/bulk-id.dto.d.ts +3 -0
  15. package/src/common/dto/bulk-id.dto.js +63 -0
  16. package/src/common/dto/bulk-id.dto.ts +13 -0
  17. package/src/common/dto/create-translation.dto.d.ts +5 -0
  18. package/src/common/dto/create-translation.dto.js +63 -0
  19. package/src/common/dto/create-translation.dto.ts +10 -0
  20. package/src/common/dto/page-meta.dto.d.ts +15 -0
  21. package/src/common/dto/page-meta.dto.js +88 -0
  22. package/src/common/dto/page-meta.dto.ts +37 -0
  23. package/src/common/dto/page-options.dto.d.ts +8 -0
  24. package/src/common/dto/page-options.dto.js +87 -0
  25. package/src/common/dto/page-options.dto.ts +35 -0
  26. package/src/common/dto/page.dto.d.ts +11 -0
  27. package/src/common/dto/page.dto.js +94 -0
  28. package/src/common/dto/page.dto.ts +36 -0
  29. package/src/common/utils.d.ts +14 -0
  30. package/src/common/utils.js +39 -0
  31. package/src/common/utils.ts +45 -0
  32. package/src/constants/index.d.ts +4 -0
  33. package/src/constants/index.js +20 -0
  34. package/src/constants/index.ts +4 -0
  35. package/src/constants/language-code.d.ts +5 -0
  36. package/src/constants/language-code.js +10 -0
  37. package/src/constants/language-code.ts +7 -0
  38. package/src/constants/order.d.ts +4 -0
  39. package/src/constants/order.js +8 -0
  40. package/src/constants/order.ts +4 -0
  41. package/src/constants/role-type.d.ts +4 -0
  42. package/src/constants/role-type.js +8 -0
  43. package/src/constants/role-type.ts +4 -0
  44. package/src/constants/token-type.d.ts +4 -0
  45. package/src/constants/token-type.js +8 -0
  46. package/src/constants/token-type.ts +4 -0
  47. package/src/decorators/api-page-ok-response.decorator.d.ts +5 -0
  48. package/src/decorators/api-page-ok-response.decorator.js +25 -0
  49. package/src/decorators/api-page-ok-response.decorator.ts +31 -0
  50. package/src/decorators/auth-user.decorator.d.ts +1 -0
  51. package/src/decorators/auth-user.decorator.js +15 -0
  52. package/src/decorators/auth-user.decorator.ts +16 -0
  53. package/src/decorators/controller.decorator.d.ts +1 -0
  54. package/src/decorators/controller.decorator.js +34 -0
  55. package/src/decorators/controller.decorator.ts +8 -0
  56. package/src/decorators/field.decorators.d.ts +71 -0
  57. package/src/decorators/field.decorators.js +455 -0
  58. package/src/decorators/field.decorators.ts +773 -0
  59. package/src/decorators/http.decorators.d.ts +3 -0
  60. package/src/decorators/http.decorators.js +8 -0
  61. package/src/decorators/http.decorators.ts +10 -0
  62. package/src/decorators/index.d.ts +12 -0
  63. package/src/decorators/index.js +28 -0
  64. package/src/decorators/index.ts +12 -0
  65. package/src/decorators/omni-auth.decorator.d.ts +8 -0
  66. package/src/decorators/omni-auth.decorator.js +60 -0
  67. package/src/decorators/omni-auth.decorator.ts +46 -0
  68. package/src/decorators/operation.decorator.d.ts +1 -0
  69. package/src/decorators/operation.decorator.js +6 -0
  70. package/src/decorators/operation.decorator.ts +4 -0
  71. package/src/decorators/property.decorators.d.ts +15 -0
  72. package/src/decorators/property.decorators.js +36 -0
  73. package/src/decorators/property.decorators.ts +62 -0
  74. package/src/decorators/public-route.decorator.d.ts +3 -0
  75. package/src/decorators/public-route.decorator.js +8 -0
  76. package/src/decorators/public-route.decorator.ts +8 -0
  77. package/src/decorators/swagger.schema.d.ts +5 -0
  78. package/src/decorators/swagger.schema.js +82 -0
  79. package/src/decorators/swagger.schema.ts +117 -0
  80. package/src/decorators/timestamp-column.decorator.d.ts +1 -0
  81. package/src/decorators/timestamp-column.decorator.js +28 -0
  82. package/src/decorators/timestamp-column.decorator.ts +29 -0
  83. package/src/decorators/transform.decorators.d.ts +35 -0
  84. package/src/decorators/transform.decorators.js +122 -0
  85. package/src/decorators/transform.decorators.ts +147 -0
  86. package/src/decorators/translate.decorator.d.ts +5 -0
  87. package/src/decorators/translate.decorator.js +18 -0
  88. package/src/decorators/translate.decorator.ts +19 -0
  89. package/src/decorators/use-dto.decorator.d.ts +4 -0
  90. package/src/decorators/use-dto.decorator.js +9 -0
  91. package/src/decorators/use-dto.decorator.ts +11 -0
  92. package/src/decorators/user-check.decorator.d.ts +6 -0
  93. package/src/decorators/user-check.decorator.js +44 -0
  94. package/src/decorators/user-check.decorator.ts +30 -0
  95. package/src/decorators/user.decorator.d.ts +8 -0
  96. package/src/decorators/user.decorator.js +62 -0
  97. package/src/decorators/user.decorator.ts +48 -0
  98. package/src/decorators/user_auth.decorator.d.ts +1 -0
  99. package/src/decorators/user_auth.decorator.js +16 -0
  100. package/src/decorators/user_auth.decorator.ts +15 -0
  101. package/src/decorators/validator.decorators.d.ts +10 -0
  102. package/src/decorators/validator.decorators.js +59 -0
  103. package/src/decorators/validator.decorators.ts +78 -0
  104. package/src/exceptions/file-not-image.exception.d.ts +4 -0
  105. package/src/exceptions/file-not-image.exception.js +10 -0
  106. package/src/exceptions/file-not-image.exception.ts +7 -0
  107. package/src/exceptions/index.d.ts +2 -0
  108. package/src/exceptions/index.js +18 -0
  109. package/src/exceptions/index.ts +2 -0
  110. package/src/exceptions/page-type.exception.d.ts +4 -0
  111. package/src/exceptions/page-type.exception.js +10 -0
  112. package/src/exceptions/page-type.exception.ts +7 -0
  113. package/src/exceptions/user-not-found.exception.d.ts +4 -0
  114. package/src/exceptions/user-not-found.exception.js +10 -0
  115. package/src/exceptions/user-not-found.exception.ts +7 -0
  116. package/src/filters/bad-request.filter.d.ts +5 -0
  117. package/src/filters/bad-request.filter.js +104 -0
  118. package/src/filters/bad-request.filter.ts +67 -0
  119. package/src/filters/constraint-errors.d.ts +1 -0
  120. package/src/filters/constraint-errors.js +7 -0
  121. package/src/filters/constraint-errors.ts +5 -0
  122. package/src/filters/index.d.ts +3 -0
  123. package/src/filters/index.js +19 -0
  124. package/src/filters/index.ts +3 -0
  125. package/src/filters/query-failed.filter.d.ts +10 -0
  126. package/src/filters/query-failed.filter.js +81 -0
  127. package/src/filters/query-failed.filter.ts +32 -0
  128. package/src/health-checker/health-checker.controller.d.ts +15 -0
  129. package/src/health-checker/health-checker.controller.js +104 -0
  130. package/src/health-checker/health-checker.controller.ts +51 -0
  131. package/src/health-checker/health-checker.module.d.ts +2 -0
  132. package/src/health-checker/health-checker.module.js +69 -0
  133. package/src/health-checker/health-checker.module.ts +13 -0
  134. package/src/health-checker/health-indicators/service.indicator.d.ts +8 -0
  135. package/src/health-checker/health-indicators/service.indicator.js +102 -0
  136. package/src/health-checker/health-indicators/service.indicator.ts +44 -0
  137. package/src/helpers/common.helper.d.ts +16 -0
  138. package/src/helpers/common.helper.js +49 -0
  139. package/src/helpers/common.helper.ts +49 -0
  140. package/src/helpers/date.helper.d.ts +10 -0
  141. package/src/helpers/date.helper.js +81 -0
  142. package/src/helpers/date.helper.ts +64 -0
  143. package/src/helpers/excel.helper.d.ts +27 -0
  144. package/src/helpers/excel.helper.js +338 -0
  145. package/src/helpers/index.d.ts +3 -0
  146. package/src/helpers/index.js +19 -0
  147. package/src/helpers/index.ts +3 -0
  148. package/src/i18n/en_US/validation.json +38 -0
  149. package/src/i18n/zh_CN/validation.json +38 -0
  150. package/src/index.d.ts +11 -0
  151. package/src/index.js +28 -0
  152. package/src/index.ts +12 -0
  153. package/src/interceptors/auth-user.interceptor.d.ts +4 -0
  154. package/src/interceptors/auth-user.interceptor.js +68 -0
  155. package/src/interceptors/auth-user.interceptor.ts +20 -0
  156. package/src/interceptors/index.d.ts +2 -0
  157. package/src/interceptors/index.js +18 -0
  158. package/src/interceptors/index.ts +2 -0
  159. package/src/interceptors/language-interceptor.service.d.ts +6 -0
  160. package/src/interceptors/language-interceptor.service.js +74 -0
  161. package/src/interceptors/language-interceptor.service.ts +31 -0
  162. package/src/interceptors/translation-interceptor.service.d.ts +5 -0
  163. package/src/interceptors/translation-interceptor.service.js +83 -0
  164. package/src/interceptors/translation-interceptor.service.ts +43 -0
  165. package/src/interfaces/IApiFile.d.ts +4 -0
  166. package/src/interfaces/IApiFile.js +2 -0
  167. package/src/interfaces/IApiFile.ts +4 -0
  168. package/src/interfaces/IFile.d.ts +9 -0
  169. package/src/interfaces/IFile.js +2 -0
  170. package/src/interfaces/IFile.ts +8 -0
  171. package/src/interfaces/ITranslationDecoratorInterface.d.ts +3 -0
  172. package/src/interfaces/ITranslationDecoratorInterface.js +2 -0
  173. package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
  174. package/src/interfaces/index.d.ts +3 -0
  175. package/src/interfaces/index.js +19 -0
  176. package/src/interfaces/index.ts +3 -0
  177. package/src/interfaces/response.d.ts +25 -0
  178. package/src/interfaces/response.js +2 -0
  179. package/src/interfaces/response.ts +37 -0
  180. package/src/middlewares/index.d.ts +3 -0
  181. package/src/middlewares/index.js +19 -0
  182. package/src/middlewares/index.ts +3 -0
  183. package/src/middlewares/omni-auth.middleware.d.ts +1 -0
  184. package/src/middlewares/omni-auth.middleware.js +13 -0
  185. package/src/middlewares/omni-auth.middleware.ts +10 -0
  186. package/src/middlewares/powerby.middleware.d.ts +1 -0
  187. package/src/middlewares/powerby.middleware.js +10 -0
  188. package/src/middlewares/powerby.middleware.ts +6 -0
  189. package/src/middlewares/request-id.middleware.d.ts +7 -0
  190. package/src/middlewares/request-id.middleware.js +22 -0
  191. package/src/middlewares/request-id.middleware.ts +28 -0
  192. package/src/providers/context.provider.d.ts +32 -0
  193. package/src/providers/context.provider.js +73 -0
  194. package/src/providers/context.provider.ts +98 -0
  195. package/src/providers/generator.provider.d.ts +13 -0
  196. package/src/providers/generator.provider.js +54 -0
  197. package/src/providers/generator.provider.ts +66 -0
  198. package/src/providers/index.d.ts +2 -0
  199. package/src/providers/index.js +18 -0
  200. package/src/providers/index.ts +2 -0
  201. package/src/setup/bootstrap.setup.d.ts +5 -0
  202. package/src/setup/bootstrap.setup.js +138 -0
  203. package/src/setup/bootstrap.setup.ts +139 -0
  204. package/src/setup/index.d.ts +1 -0
  205. package/src/setup/index.js +17 -0
  206. package/src/setup/index.ts +1 -0
  207. package/src/setup/microservices.setup.js +55 -0
  208. package/src/setup-swagger.d.ts +2 -0
  209. package/src/setup-swagger.js +62 -0
  210. package/src/setup-swagger.ts +67 -0
  211. package/src/shared/index.d.ts +2 -0
  212. package/src/shared/index.js +18 -0
  213. package/src/shared/index.ts +2 -0
  214. package/src/shared/serviceRegistryModule.d.ts +2 -0
  215. package/src/shared/serviceRegistryModule.js +176 -0
  216. package/src/shared/serviceRegistryModule.ts +110 -0
  217. package/src/shared/services/api-config.service.d.ts +73 -0
  218. package/src/shared/services/api-config.service.js +335 -0
  219. package/src/shared/services/api-config.service.ts +319 -0
  220. package/src/shared/services/aws-s3.service.d.ts +10 -0
  221. package/src/shared/services/aws-s3.service.js +96 -0
  222. package/src/shared/services/aws-s3.service.ts +39 -0
  223. package/src/shared/services/generator.service.d.ts +4 -0
  224. package/src/shared/services/generator.service.js +67 -0
  225. package/src/shared/services/generator.service.ts +13 -0
  226. package/src/shared/services/index.d.ts +5 -0
  227. package/src/shared/services/index.js +21 -0
  228. package/src/shared/services/index.ts +5 -0
  229. package/src/shared/services/translation.service.d.ts +9 -0
  230. package/src/shared/services/translation.service.js +109 -0
  231. package/src/shared/services/translation.service.ts +59 -0
  232. package/src/shared/services/validator.service.d.ts +3 -0
  233. package/src/shared/services/validator.service.js +64 -0
  234. package/src/shared/services/validator.service.ts +10 -0
  235. package/src/snake-naming.strategy.d.ts +11 -0
  236. package/src/snake-naming.strategy.js +37 -0
  237. package/src/snake-naming.strategy.ts +64 -0
  238. package/src/types.d.ts +9 -0
  239. package/src/types.js +2 -0
  240. package/src/types.ts +44 -0
  241. package/src/validators/file-mimetype.validator.d.ts +13 -0
  242. package/src/validators/file-mimetype.validator.js +21 -0
  243. package/src/validators/file-mimetype.validator.ts +34 -0
  244. package/src/validators/index.d.ts +3 -0
  245. package/src/validators/index.js +19 -0
  246. package/src/validators/index.ts +3 -0
  247. package/src/validators/is-exists.validator.d.ts +18 -0
  248. package/src/validators/is-exists.validator.js +99 -0
  249. package/src/validators/is-exists.validator.ts +60 -0
  250. package/src/validators/is-unique.validator.d.ts +17 -0
  251. package/src/validators/is-unique.validator.js +131 -0
  252. package/src/validators/is-unique.validator.ts +93 -0
  253. package/src/validators/phone-country-code.validator.d.ts +2 -0
  254. package/src/validators/phone-country-code.validator.js +30 -0
  255. package/src/validators/phone-country-code.validator.ts +36 -0
  256. package/src/validators/same-as.validator.d.ts +2 -0
  257. package/src/validators/same-as.validator.js +25 -0
  258. package/src/validators/same-as.validator.ts +27 -0
  259. package/src/validators/skip-empty.validator.d.ts +6 -0
  260. package/src/validators/skip-empty.validator.js +23 -0
  261. package/src/validators/skip-empty.validator.ts +25 -0
  262. package/tsconfig.json +26 -0
  263. package/tsconfig.lib.json +16 -0
  264. package/tsconfig.tsbuildinfo +1 -0
  265. /package/{README → README.md} +0 -0
@@ -0,0 +1,78 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ import {
3
+ IsPhoneNumber as isPhoneNumber,
4
+ registerDecorator,
5
+ ValidateIf,
6
+ } from 'class-validator';
7
+ import { isString } from 'lodash';
8
+
9
+ export function IsPassword(
10
+ validationOptions?: ValidationOptions,
11
+ ): PropertyDecorator {
12
+ return (object, propertyName: string) => {
13
+ registerDecorator({
14
+ propertyName,
15
+ name: 'isPassword',
16
+ target: object.constructor,
17
+ constraints: [],
18
+ options: validationOptions,
19
+ validator: {
20
+ validate(value: string) {
21
+ return /^[\d!#$%&*@A-Z^a-z]*$/.test(value);
22
+ },
23
+ },
24
+ });
25
+ };
26
+ }
27
+
28
+ export function IsPhoneNumber(
29
+ validationOptions?: ValidationOptions & {
30
+ region?: Parameters<typeof isPhoneNumber>[0];
31
+ },
32
+ ): PropertyDecorator {
33
+ return isPhoneNumber(validationOptions?.region, {
34
+ message: 'error.phoneNumber',
35
+ ...validationOptions,
36
+ });
37
+ }
38
+
39
+ export function IsTmpKey(
40
+ validationOptions?: ValidationOptions,
41
+ ): PropertyDecorator {
42
+ return (object, propertyName: string) => {
43
+ registerDecorator({
44
+ propertyName,
45
+ name: 'tmpKey',
46
+ target: object.constructor,
47
+ options: validationOptions,
48
+ validator: {
49
+ validate(value: string): boolean {
50
+ return isString(value) && /^tmp\//.test(value);
51
+ },
52
+ defaultMessage(): string {
53
+ return 'error.invalidTmpKey';
54
+ },
55
+ },
56
+ });
57
+ };
58
+ }
59
+
60
+ export function IsUndefinable(options?: ValidationOptions): PropertyDecorator {
61
+ return ValidateIf((obj, value) => value !== undefined, options);
62
+ }
63
+
64
+ export function IsEmptyable(options?: ValidationOptions): PropertyDecorator {
65
+ return ValidateIf(
66
+ (obj, value) =>
67
+ !(
68
+ value === null ||
69
+ value === undefined ||
70
+ (isString(value) && value.trim() === '')
71
+ ),
72
+ options,
73
+ );
74
+ }
75
+
76
+ export function IsNullable(options?: ValidationOptions): PropertyDecorator {
77
+ return ValidateIf((obj, value) => value !== null, options);
78
+ }
@@ -0,0 +1,4 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+ export declare class FileNotImageException extends BadRequestException {
3
+ constructor(error?: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileNotImageException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ class FileNotImageException extends common_1.BadRequestException {
6
+ constructor(error) {
7
+ super('error.fileNotImage', error);
8
+ }
9
+ }
10
+ exports.FileNotImageException = FileNotImageException;
@@ -0,0 +1,7 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+
3
+ export class FileNotImageException extends BadRequestException {
4
+ constructor(error?: string) {
5
+ super('error.fileNotImage', error);
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from './file-not-image.exception';
2
+ export * from './user-not-found.exception';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./file-not-image.exception"), exports);
18
+ __exportStar(require("./user-not-found.exception"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './file-not-image.exception';
2
+ export * from './user-not-found.exception';
@@ -0,0 +1,4 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+ export declare class PageTypeException extends BadRequestException {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageTypeException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ class PageTypeException extends common_1.BadRequestException {
6
+ constructor() {
7
+ super('error.pageType');
8
+ }
9
+ }
10
+ exports.PageTypeException = PageTypeException;
@@ -0,0 +1,7 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+
3
+ export class PageTypeException extends BadRequestException {
4
+ constructor() {
5
+ super('error.pageType');
6
+ }
7
+ }
@@ -0,0 +1,4 @@
1
+ import { NotFoundException } from '@nestjs/common';
2
+ export declare class UserNotFoundException extends NotFoundException {
3
+ constructor(error?: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserNotFoundException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ class UserNotFoundException extends common_1.NotFoundException {
6
+ constructor(error) {
7
+ super('error.userNotFound', error);
8
+ }
9
+ }
10
+ exports.UserNotFoundException = UserNotFoundException;
@@ -0,0 +1,7 @@
1
+ import { NotFoundException } from '@nestjs/common';
2
+
3
+ export class UserNotFoundException extends NotFoundException {
4
+ constructor(error?: string) {
5
+ super('error.userNotFound', error);
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ import { Response } from 'express';
3
+ export declare class HttpExceptionFilter implements ExceptionFilter {
4
+ catch(exception: any, host: ArgumentsHost): Response<any, Record<string, any>>;
5
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.HttpExceptionFilter = void 0;
42
+ const common_1 = require("@nestjs/common");
43
+ const typeorm_1 = require("typeorm");
44
+ const nestjs_i18n_1 = require("nestjs-i18n");
45
+ let HttpExceptionFilter = (() => {
46
+ let _classDecorators = [(0, common_1.Catch)()];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ var HttpExceptionFilter = _classThis = class {
51
+ catch(exception, host) {
52
+ const i18n = nestjs_i18n_1.I18nContext.current(host);
53
+ const ctx = host.switchToHttp();
54
+ const response = ctx.getResponse();
55
+ const request = ctx.getRequest();
56
+ let statusCode = exception instanceof common_1.HttpException ? exception.getStatus() : 500;
57
+ let error = exception instanceof common_1.HttpException
58
+ ? exception.message
59
+ : 'Internal server error';
60
+ if (exception instanceof typeorm_1.EntityNotFoundError) {
61
+ statusCode = 404;
62
+ error = 'Entity not found';
63
+ }
64
+ if (statusCode === 500) {
65
+ console.error(exception);
66
+ }
67
+ const getFirstError = (error, property = '') => {
68
+ var _a;
69
+ if (((_a = error === null || error === void 0 ? void 0 : error.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
70
+ const firstError = error.children[0];
71
+ firstError['property'] = `${property}.${firstError['property']}`;
72
+ return getFirstError(firstError, firstError.property);
73
+ }
74
+ return error;
75
+ };
76
+ if (exception instanceof nestjs_i18n_1.I18nValidationException) {
77
+ const firstErros = getFirstError(exception.errors[0], exception.errors[0].property);
78
+ const constraint = Object.values(firstErros.constraints)[0];
79
+ const [translationKey, argsString] = constraint.split('|');
80
+ const args = !!argsString ? JSON.parse(argsString) : {};
81
+ error = i18n.translate(translationKey, {
82
+ args: Object.assign({ property: firstErros.property, value: firstErros.value, constraints: firstErros.constraints }, args),
83
+ });
84
+ }
85
+ const parseJson = {
86
+ code: statusCode,
87
+ msg: error,
88
+ requestId: request.id,
89
+ timestamp: new Date().toISOString(),
90
+ };
91
+ return response.status(200).json(parseJson);
92
+ }
93
+ };
94
+ __setFunctionName(_classThis, "HttpExceptionFilter");
95
+ (() => {
96
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
97
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
98
+ HttpExceptionFilter = _classThis = _classDescriptor.value;
99
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
100
+ __runInitializers(_classThis, _classExtraInitializers);
101
+ })();
102
+ return HttpExceptionFilter = _classThis;
103
+ })();
104
+ exports.HttpExceptionFilter = HttpExceptionFilter;
@@ -0,0 +1,67 @@
1
+ import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ import { Catch, HttpException } from '@nestjs/common';
3
+ import { Request, Response } from 'express';
4
+ import { EntityNotFoundError } from 'typeorm';
5
+ import { I18nContext, I18nValidationException } from 'nestjs-i18n';
6
+
7
+ @Catch()
8
+ export class HttpExceptionFilter implements ExceptionFilter {
9
+ catch(exception, host: ArgumentsHost) {
10
+ const i18n = I18nContext.current(host);
11
+ const ctx = host.switchToHttp();
12
+ const response: Response = ctx.getResponse();
13
+ const request: Request = ctx.getRequest();
14
+ let statusCode =
15
+ exception instanceof HttpException ? exception.getStatus() : 500;
16
+ let error =
17
+ exception instanceof HttpException
18
+ ? exception.message
19
+ : 'Internal server error';
20
+
21
+ if (exception instanceof EntityNotFoundError) {
22
+ statusCode = 404;
23
+ error = 'Entity not found';
24
+ }
25
+
26
+ if (statusCode === 500) {
27
+ console.error(exception);
28
+ }
29
+
30
+ const getFirstError = (error, property = '') => {
31
+ if (error?.children?.length > 0) {
32
+ const firstError = error.children[0];
33
+ firstError['property'] = `${property}.${firstError['property']}`;
34
+ return getFirstError(firstError, firstError.property);
35
+ }
36
+
37
+ return error;
38
+ };
39
+
40
+ if (exception instanceof I18nValidationException) {
41
+ const firstErros = getFirstError(
42
+ exception.errors[0],
43
+ exception.errors[0].property,
44
+ );
45
+ const constraint = Object.values(firstErros.constraints)[0] as string;
46
+ const [translationKey, argsString] = constraint.split('|');
47
+ const args = !!argsString ? JSON.parse(argsString) : {};
48
+ error = i18n.translate(translationKey, {
49
+ args: {
50
+ property: firstErros.property,
51
+ value: firstErros.value,
52
+ constraints: firstErros.constraints,
53
+ ...args,
54
+ },
55
+ });
56
+ }
57
+
58
+ const parseJson = {
59
+ code: statusCode,
60
+ msg: error,
61
+ requestId: request.id,
62
+ timestamp: new Date().toISOString(),
63
+ };
64
+
65
+ return response.status(200).json(parseJson);
66
+ }
67
+ }
@@ -0,0 +1 @@
1
+ export declare const constraintErrors: Record<string, string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.constraintErrors = void 0;
5
+ exports.constraintErrors = {
6
+ UQ_97672ac88f789774dd47f7c8be3: 'error.unique.email',
7
+ };
@@ -0,0 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+
3
+ export const constraintErrors: Record<string, string> = {
4
+ UQ_97672ac88f789774dd47f7c8be3: 'error.unique.email',
5
+ };
@@ -0,0 +1,3 @@
1
+ export * from './bad-request.filter';
2
+ export * from './constraint-errors';
3
+ export * from './query-failed.filter';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bad-request.filter"), exports);
18
+ __exportStar(require("./constraint-errors"), exports);
19
+ __exportStar(require("./query-failed.filter"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './bad-request.filter';
2
+ export * from './constraint-errors';
3
+ export * from './query-failed.filter';
@@ -0,0 +1,10 @@
1
+ import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { QueryFailedError } from 'typeorm';
4
+ export declare class QueryFailedFilter implements ExceptionFilter<QueryFailedError> {
5
+ reflector: Reflector;
6
+ constructor(reflector: Reflector);
7
+ catch(exception: QueryFailedError & {
8
+ constraint?: string;
9
+ }, host: ArgumentsHost): void;
10
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.QueryFailedFilter = void 0;
42
+ const common_1 = require("@nestjs/common");
43
+ const http_1 = require("http");
44
+ const typeorm_1 = require("typeorm");
45
+ const constraint_errors_1 = require("./constraint-errors");
46
+ let QueryFailedFilter = (() => {
47
+ let _classDecorators = [(0, common_1.Catch)(typeorm_1.QueryFailedError)];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ var QueryFailedFilter = _classThis = class {
52
+ constructor(reflector) {
53
+ this.reflector = reflector;
54
+ }
55
+ catch(exception, host) {
56
+ var _a;
57
+ const ctx = host.switchToHttp();
58
+ const response = ctx.getResponse();
59
+ const status = ((_a = exception.constraint) === null || _a === void 0 ? void 0 : _a.startsWith('UQ'))
60
+ ? common_1.HttpStatus.CONFLICT
61
+ : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
62
+ response.status(status).json({
63
+ code: status,
64
+ error: http_1.STATUS_CODES[status],
65
+ msg: exception.constraint
66
+ ? constraint_errors_1.constraintErrors[exception.constraint]
67
+ : undefined,
68
+ });
69
+ }
70
+ };
71
+ __setFunctionName(_classThis, "QueryFailedFilter");
72
+ (() => {
73
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
74
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
75
+ QueryFailedFilter = _classThis = _classDescriptor.value;
76
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
77
+ __runInitializers(_classThis, _classExtraInitializers);
78
+ })();
79
+ return QueryFailedFilter = _classThis;
80
+ })();
81
+ exports.QueryFailedFilter = QueryFailedFilter;
@@ -0,0 +1,32 @@
1
+ import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ import { Catch, HttpStatus } from '@nestjs/common';
3
+ import { Reflector } from '@nestjs/core';
4
+ import { STATUS_CODES } from 'http';
5
+ import { QueryFailedError } from 'typeorm';
6
+
7
+ import { constraintErrors } from './constraint-errors';
8
+
9
+ @Catch(QueryFailedError)
10
+ export class QueryFailedFilter implements ExceptionFilter<QueryFailedError> {
11
+ constructor(public reflector: Reflector) {}
12
+
13
+ catch(
14
+ exception: QueryFailedError & { constraint?: string },
15
+ host: ArgumentsHost,
16
+ ) {
17
+ const ctx = host.switchToHttp();
18
+ const response = ctx.getResponse();
19
+
20
+ const status = exception.constraint?.startsWith('UQ')
21
+ ? HttpStatus.CONFLICT
22
+ : HttpStatus.INTERNAL_SERVER_ERROR;
23
+
24
+ response.status(status).json({
25
+ code: status,
26
+ error: STATUS_CODES[status],
27
+ msg: exception.constraint
28
+ ? constraintErrors[exception.constraint]
29
+ : undefined,
30
+ });
31
+ }
32
+ }
@@ -0,0 +1,15 @@
1
+ import type { HealthCheckResult } from '@nestjs/terminus';
2
+ import { HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
3
+ import { ServiceHealthIndicator } from './health-indicators/service.indicator';
4
+ import { RedisHealthIndicator } from '@liaoliaots/nestjs-redis-health';
5
+ import { ApiConfigService } from '../shared/services';
6
+ export declare class HealthCheckerController {
7
+ private configService;
8
+ private healthCheckService;
9
+ private ormIndicator;
10
+ private serviceIndicator;
11
+ private redisIndicator;
12
+ private readonly redis;
13
+ constructor(configService: ApiConfigService, healthCheckService: HealthCheckService, ormIndicator: TypeOrmHealthIndicator, serviceIndicator: ServiceHealthIndicator, redisIndicator: RedisHealthIndicator);
14
+ check(): Promise<HealthCheckResult>;
15
+ }