@nest-omni/core 1.0.6 → 1.0.8
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.
- package/{src → dist}/boilerplate.polyfill.js +0 -1
- package/{src → dist}/common/abstract-client.service.d.ts +0 -4
- package/{src → dist}/common/abstract-client.service.js +0 -4
- package/{src → dist}/common/abstract.entity.d.ts +0 -7
- package/dist/common/abstract.entity.js +64 -0
- package/dist/common/dto/abstract.dto.js +59 -0
- package/dist/common/dto/bulk-id.dto.js +27 -0
- package/dist/common/dto/create-translation.dto.js +25 -0
- package/dist/common/dto/page-meta.dto.js +48 -0
- package/dist/common/dto/page-options.dto.js +52 -0
- package/dist/common/dto/page.dto.js +53 -0
- package/{src → dist}/common/utils.d.ts +0 -11
- package/{src → dist}/common/utils.js +1 -15
- package/{src → dist}/constants/language-code.js +0 -1
- package/dist/decorators/controller.decorator.js +11 -0
- package/{src → dist}/decorators/field.decorators.js +1 -7
- package/{src → dist}/decorators/omni-auth.decorator.js +1 -26
- package/{src → dist}/decorators/property.decorators.js +1 -5
- package/{src → dist}/decorators/public-route.decorator.js +0 -1
- package/{src → dist}/decorators/swagger.schema.js +1 -4
- package/{src → dist}/decorators/timestamp-column.decorator.js +1 -1
- package/dist/decorators/transform.decorators.d.ts +8 -0
- package/{src → dist}/decorators/transform.decorators.js +0 -27
- package/{src → dist}/decorators/translate.decorator.js +0 -1
- package/dist/decorators/user-check.decorator.js +21 -0
- package/{src → dist}/decorators/user.decorator.js +1 -25
- package/dist/filters/bad-request.filter.js +60 -0
- package/{src → dist}/filters/constraint-errors.js +0 -1
- package/dist/filters/query-failed.filter.js +42 -0
- package/dist/health-checker/health-checker.controller.js +72 -0
- package/dist/health-checker/health-checker.module.js +25 -0
- package/dist/health-checker/health-indicators/service.indicator.js +66 -0
- package/dist/helpers/common.helper.d.ts +3 -0
- package/{src → dist}/helpers/common.helper.js +0 -13
- package/{src → dist}/helpers/date.helper.d.ts +3 -3
- package/{src → dist}/helpers/date.helper.js +2 -25
- package/dist/i18n/en_US/validation.json +38 -0
- package/dist/i18n/zh_CN/validation.json +38 -0
- package/{src → dist}/index.js +0 -1
- package/dist/interceptors/auth-user.interceptor.js +24 -0
- package/dist/interceptors/language-interceptor.service.js +30 -0
- package/dist/interceptors/translation-interceptor.service.js +34 -0
- package/{src → dist}/providers/context.provider.js +0 -2
- package/{src → dist}/providers/generator.provider.d.ts +0 -4
- package/{src → dist}/providers/generator.provider.js +0 -4
- package/{src → dist}/setup/bootstrap.setup.js +7 -33
- package/dist/shared/serviceRegistryModule.js +110 -0
- package/{src → dist}/shared/services/api-config.service.d.ts +0 -3
- package/dist/shared/services/api-config.service.js +290 -0
- package/dist/shared/services/aws-s3.service.js +56 -0
- package/dist/shared/services/generator.service.js +23 -0
- package/dist/shared/services/translation.service.js +70 -0
- package/dist/shared/services/validator.service.js +20 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/validators/is-exists.validator.js +61 -0
- package/dist/validators/is-unique.validator.js +92 -0
- package/{src → dist}/validators/skip-empty.validator.d.ts +0 -5
- package/{src → dist}/validators/skip-empty.validator.js +0 -5
- package/package.json +4 -1
- package/src/boilerplate.polyfill.ts +0 -202
- package/src/common/abstract-client.service.ts +0 -56
- package/src/common/abstract.entity.js +0 -152
- package/src/common/abstract.entity.ts +0 -73
- package/src/common/dto/abstract.dto.js +0 -96
- package/src/common/dto/abstract.dto.ts +0 -64
- package/src/common/dto/bulk-id.dto.js +0 -63
- package/src/common/dto/bulk-id.dto.ts +0 -13
- package/src/common/dto/create-translation.dto.js +0 -63
- package/src/common/dto/create-translation.dto.ts +0 -10
- package/src/common/dto/page-meta.dto.js +0 -88
- package/src/common/dto/page-meta.dto.ts +0 -37
- package/src/common/dto/page-options.dto.js +0 -87
- package/src/common/dto/page-options.dto.ts +0 -35
- package/src/common/dto/page.dto.js +0 -94
- package/src/common/dto/page.dto.ts +0 -36
- package/src/common/utils.ts +0 -45
- package/src/constants/index.ts +0 -4
- package/src/constants/language-code.ts +0 -7
- package/src/constants/order.ts +0 -4
- package/src/constants/role-type.ts +0 -4
- package/src/constants/token-type.ts +0 -4
- package/src/decorators/api-page-ok-response.decorator.ts +0 -31
- package/src/decorators/auth-user.decorator.ts +0 -16
- package/src/decorators/controller.decorator.js +0 -34
- package/src/decorators/controller.decorator.ts +0 -8
- package/src/decorators/field.decorators.ts +0 -773
- package/src/decorators/http.decorators.ts +0 -10
- package/src/decorators/index.ts +0 -12
- package/src/decorators/omni-auth.decorator.ts +0 -46
- package/src/decorators/operation.decorator.ts +0 -4
- package/src/decorators/property.decorators.ts +0 -62
- package/src/decorators/public-route.decorator.ts +0 -8
- package/src/decorators/swagger.schema.ts +0 -117
- package/src/decorators/timestamp-column.decorator.ts +0 -29
- package/src/decorators/transform.decorators.d.ts +0 -35
- package/src/decorators/transform.decorators.ts +0 -147
- package/src/decorators/translate.decorator.ts +0 -19
- package/src/decorators/use-dto.decorator.ts +0 -11
- package/src/decorators/user-check.decorator.js +0 -44
- package/src/decorators/user-check.decorator.ts +0 -30
- package/src/decorators/user.decorator.ts +0 -48
- package/src/decorators/user_auth.decorator.ts +0 -15
- package/src/decorators/validator.decorators.ts +0 -78
- package/src/exceptions/file-not-image.exception.ts +0 -7
- package/src/exceptions/index.ts +0 -2
- package/src/exceptions/page-type.exception.ts +0 -7
- package/src/exceptions/user-not-found.exception.ts +0 -7
- package/src/filters/bad-request.filter.js +0 -104
- package/src/filters/bad-request.filter.ts +0 -67
- package/src/filters/constraint-errors.ts +0 -5
- package/src/filters/index.ts +0 -3
- package/src/filters/query-failed.filter.js +0 -81
- package/src/filters/query-failed.filter.ts +0 -32
- package/src/health-checker/health-checker.controller.js +0 -104
- package/src/health-checker/health-checker.controller.ts +0 -51
- package/src/health-checker/health-checker.module.js +0 -69
- package/src/health-checker/health-checker.module.ts +0 -13
- package/src/health-checker/health-indicators/service.indicator.js +0 -102
- package/src/health-checker/health-indicators/service.indicator.ts +0 -44
- package/src/helpers/common.helper.d.ts +0 -16
- package/src/helpers/common.helper.ts +0 -49
- package/src/helpers/date.helper.ts +0 -64
- package/src/helpers/excel.helper.d.ts +0 -27
- package/src/helpers/excel.helper.js +0 -338
- package/src/helpers/index.ts +0 -3
- package/src/i18n/en_US/validation.json +0 -38
- package/src/i18n/zh_CN/validation.json +0 -38
- package/src/index.ts +0 -12
- package/src/interceptors/auth-user.interceptor.js +0 -68
- package/src/interceptors/auth-user.interceptor.ts +0 -20
- package/src/interceptors/index.ts +0 -2
- package/src/interceptors/language-interceptor.service.js +0 -74
- package/src/interceptors/language-interceptor.service.ts +0 -31
- package/src/interceptors/translation-interceptor.service.js +0 -83
- package/src/interceptors/translation-interceptor.service.ts +0 -43
- package/src/interfaces/IApiFile.ts +0 -4
- package/src/interfaces/IFile.ts +0 -8
- package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
- package/src/interfaces/index.ts +0 -3
- package/src/interfaces/response.ts +0 -37
- package/src/middlewares/index.ts +0 -3
- package/src/middlewares/omni-auth.middleware.ts +0 -10
- package/src/middlewares/powerby.middleware.ts +0 -6
- package/src/middlewares/request-id.middleware.ts +0 -28
- package/src/providers/context.provider.ts +0 -98
- package/src/providers/generator.provider.ts +0 -66
- package/src/providers/index.ts +0 -2
- package/src/setup/bootstrap.setup.ts +0 -139
- package/src/setup/index.ts +0 -1
- package/src/setup/microservices.setup.js +0 -55
- package/src/setup-swagger.ts +0 -67
- package/src/shared/index.ts +0 -2
- package/src/shared/serviceRegistryModule.js +0 -176
- package/src/shared/serviceRegistryModule.ts +0 -110
- package/src/shared/services/api-config.service.js +0 -335
- package/src/shared/services/api-config.service.ts +0 -319
- package/src/shared/services/aws-s3.service.js +0 -96
- package/src/shared/services/aws-s3.service.ts +0 -39
- package/src/shared/services/generator.service.js +0 -67
- package/src/shared/services/generator.service.ts +0 -13
- package/src/shared/services/index.ts +0 -5
- package/src/shared/services/translation.service.js +0 -109
- package/src/shared/services/translation.service.ts +0 -59
- package/src/shared/services/validator.service.js +0 -64
- package/src/shared/services/validator.service.ts +0 -10
- package/src/snake-naming.strategy.ts +0 -64
- package/src/types.ts +0 -44
- package/src/validators/file-mimetype.validator.ts +0 -34
- package/src/validators/index.ts +0 -3
- package/src/validators/is-exists.validator.js +0 -99
- package/src/validators/is-exists.validator.ts +0 -60
- package/src/validators/is-unique.validator.js +0 -131
- package/src/validators/is-unique.validator.ts +0 -93
- package/src/validators/phone-country-code.validator.ts +0 -36
- package/src/validators/same-as.validator.ts +0 -27
- package/src/validators/skip-empty.validator.ts +0 -25
- package/tsconfig.json +0 -26
- package/tsconfig.lib.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/boilerplate.polyfill.d.ts +0 -0
- /package/{src → dist}/common/dto/abstract.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/bulk-id.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/create-translation.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page-meta.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page-options.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page.dto.d.ts +0 -0
- /package/{src → dist}/constants/index.d.ts +0 -0
- /package/{src → dist}/constants/index.js +0 -0
- /package/{src → dist}/constants/language-code.d.ts +0 -0
- /package/{src → dist}/constants/order.d.ts +0 -0
- /package/{src → dist}/constants/order.js +0 -0
- /package/{src → dist}/constants/role-type.d.ts +0 -0
- /package/{src → dist}/constants/role-type.js +0 -0
- /package/{src → dist}/constants/token-type.d.ts +0 -0
- /package/{src → dist}/constants/token-type.js +0 -0
- /package/{src → dist}/decorators/api-page-ok-response.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/api-page-ok-response.decorator.js +0 -0
- /package/{src → dist}/decorators/auth-user.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/auth-user.decorator.js +0 -0
- /package/{src → dist}/decorators/controller.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/field.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/http.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/http.decorators.js +0 -0
- /package/{src → dist}/decorators/index.d.ts +0 -0
- /package/{src → dist}/decorators/index.js +0 -0
- /package/{src → dist}/decorators/omni-auth.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/operation.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/operation.decorator.js +0 -0
- /package/{src → dist}/decorators/property.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/public-route.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/swagger.schema.d.ts +0 -0
- /package/{src → dist}/decorators/timestamp-column.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/translate.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/use-dto.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/use-dto.decorator.js +0 -0
- /package/{src → dist}/decorators/user-check.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user_auth.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user_auth.decorator.js +0 -0
- /package/{src → dist}/decorators/validator.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/validator.decorators.js +0 -0
- /package/{src → dist}/exceptions/file-not-image.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/file-not-image.exception.js +0 -0
- /package/{src → dist}/exceptions/index.d.ts +0 -0
- /package/{src → dist}/exceptions/index.js +0 -0
- /package/{src → dist}/exceptions/page-type.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/page-type.exception.js +0 -0
- /package/{src → dist}/exceptions/user-not-found.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/user-not-found.exception.js +0 -0
- /package/{src → dist}/filters/bad-request.filter.d.ts +0 -0
- /package/{src → dist}/filters/constraint-errors.d.ts +0 -0
- /package/{src → dist}/filters/index.d.ts +0 -0
- /package/{src → dist}/filters/index.js +0 -0
- /package/{src → dist}/filters/query-failed.filter.d.ts +0 -0
- /package/{src → dist}/health-checker/health-checker.controller.d.ts +0 -0
- /package/{src → dist}/health-checker/health-checker.module.d.ts +0 -0
- /package/{src → dist}/health-checker/health-indicators/service.indicator.d.ts +0 -0
- /package/{src → dist}/helpers/index.d.ts +0 -0
- /package/{src → dist}/helpers/index.js +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/interceptors/auth-user.interceptor.d.ts +0 -0
- /package/{src → dist}/interceptors/index.d.ts +0 -0
- /package/{src → dist}/interceptors/index.js +0 -0
- /package/{src → dist}/interceptors/language-interceptor.service.d.ts +0 -0
- /package/{src → dist}/interceptors/translation-interceptor.service.d.ts +0 -0
- /package/{src → dist}/interfaces/IApiFile.d.ts +0 -0
- /package/{src → dist}/interfaces/IApiFile.js +0 -0
- /package/{src → dist}/interfaces/IFile.d.ts +0 -0
- /package/{src → dist}/interfaces/IFile.js +0 -0
- /package/{src → dist}/interfaces/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{src → dist}/interfaces/ITranslationDecoratorInterface.js +0 -0
- /package/{src → dist}/interfaces/index.d.ts +0 -0
- /package/{src → dist}/interfaces/index.js +0 -0
- /package/{src → dist}/interfaces/response.d.ts +0 -0
- /package/{src → dist}/interfaces/response.js +0 -0
- /package/{src → dist}/middlewares/index.d.ts +0 -0
- /package/{src → dist}/middlewares/index.js +0 -0
- /package/{src → dist}/middlewares/omni-auth.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/omni-auth.middleware.js +0 -0
- /package/{src → dist}/middlewares/powerby.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/powerby.middleware.js +0 -0
- /package/{src → dist}/middlewares/request-id.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/request-id.middleware.js +0 -0
- /package/{src → dist}/providers/context.provider.d.ts +0 -0
- /package/{src → dist}/providers/index.d.ts +0 -0
- /package/{src → dist}/providers/index.js +0 -0
- /package/{src → dist}/setup/bootstrap.setup.d.ts +0 -0
- /package/{src → dist}/setup/index.d.ts +0 -0
- /package/{src → dist}/setup/index.js +0 -0
- /package/{src → dist}/setup-swagger.d.ts +0 -0
- /package/{src → dist}/setup-swagger.js +0 -0
- /package/{src → dist}/shared/index.d.ts +0 -0
- /package/{src → dist}/shared/index.js +0 -0
- /package/{src → dist}/shared/serviceRegistryModule.d.ts +0 -0
- /package/{src → dist}/shared/services/aws-s3.service.d.ts +0 -0
- /package/{src → dist}/shared/services/generator.service.d.ts +0 -0
- /package/{src → dist}/shared/services/index.d.ts +0 -0
- /package/{src → dist}/shared/services/index.js +0 -0
- /package/{src → dist}/shared/services/translation.service.d.ts +0 -0
- /package/{src → dist}/shared/services/validator.service.d.ts +0 -0
- /package/{src → dist}/snake-naming.strategy.d.ts +0 -0
- /package/{src → dist}/snake-naming.strategy.js +0 -0
- /package/{src → dist}/types.d.ts +0 -0
- /package/{src → dist}/types.js +0 -0
- /package/{src → dist}/validators/file-mimetype.validator.d.ts +0 -0
- /package/{src → dist}/validators/file-mimetype.validator.js +0 -0
- /package/{src → dist}/validators/index.d.ts +0 -0
- /package/{src → dist}/validators/index.js +0 -0
- /package/{src → dist}/validators/is-exists.validator.d.ts +0 -0
- /package/{src → dist}/validators/is-unique.validator.d.ts +0 -0
- /package/{src → dist}/validators/phone-country-code.validator.d.ts +0 -0
- /package/{src → dist}/validators/phone-country-code.validator.js +0 -0
- /package/{src → dist}/validators/same-as.validator.d.ts +0 -0
- /package/{src → dist}/validators/same-as.validator.js +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
}
|
package/src/exceptions/index.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
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;
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
}
|
package/src/filters/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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;
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
-
var useValue = arguments.length > 2;
|
|
4
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
-
}
|
|
7
|
-
return useValue ? value : void 0;
|
|
8
|
-
};
|
|
9
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
-
var _, done = false;
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
-
var context = {};
|
|
17
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
-
if (kind === "accessor") {
|
|
22
|
-
if (result === void 0) continue;
|
|
23
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
-
}
|
|
28
|
-
else if (_ = accept(result)) {
|
|
29
|
-
if (kind === "field") initializers.unshift(_);
|
|
30
|
-
else descriptor[key] = _;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
-
done = true;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
-
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
-
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.HealthCheckerController = void 0;
|
|
54
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
|
55
|
-
const common_1 = require("@nestjs/common");
|
|
56
|
-
const terminus_1 = require("@nestjs/terminus");
|
|
57
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
58
|
-
let HealthCheckerController = (() => {
|
|
59
|
-
let _classDecorators = [(0, common_1.Controller)('health')];
|
|
60
|
-
let _classDescriptor;
|
|
61
|
-
let _classExtraInitializers = [];
|
|
62
|
-
let _classThis;
|
|
63
|
-
let _instanceExtraInitializers = [];
|
|
64
|
-
let _check_decorators;
|
|
65
|
-
var HealthCheckerController = _classThis = class {
|
|
66
|
-
constructor(configService, healthCheckService, ormIndicator, serviceIndicator, redisIndicator) {
|
|
67
|
-
this.configService = (__runInitializers(this, _instanceExtraInitializers), configService);
|
|
68
|
-
this.healthCheckService = healthCheckService;
|
|
69
|
-
this.ormIndicator = ormIndicator;
|
|
70
|
-
this.serviceIndicator = serviceIndicator;
|
|
71
|
-
this.redisIndicator = redisIndicator;
|
|
72
|
-
if (this.configService.isRedisEnabled) {
|
|
73
|
-
this.redis = new ioredis_1.default(this.configService.ioRedisConfig);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
check() {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const indicator = [
|
|
79
|
-
() => this.ormIndicator.pingCheck('database', { timeout: 1500 }),
|
|
80
|
-
];
|
|
81
|
-
if (this.configService.isRedisEnabled) {
|
|
82
|
-
indicator.push(() => this.redisIndicator.checkHealth('redis', {
|
|
83
|
-
type: 'redis',
|
|
84
|
-
client: this.redis,
|
|
85
|
-
timeout: 1500,
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
return this.healthCheckService.check(indicator);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
__setFunctionName(_classThis, "HealthCheckerController");
|
|
93
|
-
(() => {
|
|
94
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
95
|
-
_check_decorators = [(0, common_1.Get)(), (0, terminus_1.HealthCheck)(), (0, swagger_1.ApiOperation)({ summary: 'Service health check' })];
|
|
96
|
-
__esDecorate(_classThis, null, _check_decorators, { kind: "method", name: "check", static: false, private: false, access: { has: obj => "check" in obj, get: obj => obj.check }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
97
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
98
|
-
HealthCheckerController = _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 HealthCheckerController = _classThis;
|
|
103
|
-
})();
|
|
104
|
-
exports.HealthCheckerController = HealthCheckerController;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
2
|
-
import { Controller, Get } from '@nestjs/common';
|
|
3
|
-
import type { HealthCheckResult } from '@nestjs/terminus';
|
|
4
|
-
import {
|
|
5
|
-
HealthCheck,
|
|
6
|
-
HealthCheckService,
|
|
7
|
-
TypeOrmHealthIndicator,
|
|
8
|
-
} from '@nestjs/terminus';
|
|
9
|
-
|
|
10
|
-
import { ServiceHealthIndicator } from './health-indicators/service.indicator';
|
|
11
|
-
import { ApiOperation } from '@nestjs/swagger';
|
|
12
|
-
import { RedisHealthIndicator } from '@liaoliaots/nestjs-redis-health';
|
|
13
|
-
import { ApiConfigService } from '../shared/services';
|
|
14
|
-
|
|
15
|
-
@Controller('health')
|
|
16
|
-
export class HealthCheckerController {
|
|
17
|
-
private readonly redis: Redis;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
private configService: ApiConfigService,
|
|
21
|
-
private healthCheckService: HealthCheckService,
|
|
22
|
-
private ormIndicator: TypeOrmHealthIndicator,
|
|
23
|
-
private serviceIndicator: ServiceHealthIndicator,
|
|
24
|
-
private redisIndicator: RedisHealthIndicator,
|
|
25
|
-
) {
|
|
26
|
-
if (this.configService.isRedisEnabled) {
|
|
27
|
-
this.redis = new Redis(this.configService.ioRedisConfig);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Get()
|
|
32
|
-
@HealthCheck()
|
|
33
|
-
@ApiOperation({ summary: 'Service health check' })
|
|
34
|
-
async check(): Promise<HealthCheckResult> {
|
|
35
|
-
const indicator = [
|
|
36
|
-
() => this.ormIndicator.pingCheck('database', { timeout: 1500 }),
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
if (this.configService.isRedisEnabled) {
|
|
40
|
-
indicator.push(() =>
|
|
41
|
-
this.redisIndicator.checkHealth('redis', {
|
|
42
|
-
type: 'redis',
|
|
43
|
-
client: this.redis,
|
|
44
|
-
timeout: 1500,
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return this.healthCheckService.check(indicator);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
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.HealthCheckerModule = void 0;
|
|
42
|
-
const common_1 = require("@nestjs/common");
|
|
43
|
-
const terminus_1 = require("@nestjs/terminus");
|
|
44
|
-
const nestjs_redis_health_1 = require("@liaoliaots/nestjs-redis-health");
|
|
45
|
-
const health_checker_controller_1 = require("./health-checker.controller");
|
|
46
|
-
const service_indicator_1 = require("./health-indicators/service.indicator");
|
|
47
|
-
const services_1 = require("../shared/services");
|
|
48
|
-
let HealthCheckerModule = (() => {
|
|
49
|
-
let _classDecorators = [(0, common_1.Module)({
|
|
50
|
-
imports: [terminus_1.TerminusModule, nestjs_redis_health_1.RedisHealthModule],
|
|
51
|
-
controllers: [health_checker_controller_1.HealthCheckerController],
|
|
52
|
-
providers: [services_1.ApiConfigService, service_indicator_1.ServiceHealthIndicator],
|
|
53
|
-
})];
|
|
54
|
-
let _classDescriptor;
|
|
55
|
-
let _classExtraInitializers = [];
|
|
56
|
-
let _classThis;
|
|
57
|
-
var HealthCheckerModule = _classThis = class {
|
|
58
|
-
};
|
|
59
|
-
__setFunctionName(_classThis, "HealthCheckerModule");
|
|
60
|
-
(() => {
|
|
61
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
62
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
63
|
-
HealthCheckerModule = _classThis = _classDescriptor.value;
|
|
64
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
65
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
66
|
-
})();
|
|
67
|
-
return HealthCheckerModule = _classThis;
|
|
68
|
-
})();
|
|
69
|
-
exports.HealthCheckerModule = HealthCheckerModule;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { TerminusModule } from '@nestjs/terminus';
|
|
3
|
-
import { RedisHealthModule } from '@liaoliaots/nestjs-redis-health';
|
|
4
|
-
import { HealthCheckerController } from './health-checker.controller';
|
|
5
|
-
import { ServiceHealthIndicator } from './health-indicators/service.indicator';
|
|
6
|
-
import { ApiConfigService } from '../shared/services';
|
|
7
|
-
|
|
8
|
-
@Module({
|
|
9
|
-
imports: [TerminusModule, RedisHealthModule],
|
|
10
|
-
controllers: [HealthCheckerController],
|
|
11
|
-
providers: [ApiConfigService, ServiceHealthIndicator],
|
|
12
|
-
})
|
|
13
|
-
export class HealthCheckerModule {}
|