@nest-omni/core 2.0.1-0 → 2.0.1-1
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/package.json +1 -1
- package/.history/src/common/boilerplate.polyfill_20250521135408.ts +0 -202
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +0 -291
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +0 -317
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +0 -319
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +0 -289
- package/README.md +0 -16
- package/build.sh +0 -45
- package/dist/package.json +0 -71
- package/dist/yarn.lock +0 -644
- package/src/.hygen.js +0 -116
- package/src/common/abstract-client.service.ts +0 -56
- package/src/common/abstract.entity.ts +0 -82
- package/src/common/boilerplate.polyfill.ts +0 -202
- package/src/common/dto/abstract.dto.ts +0 -61
- package/src/common/dto/bulk-id.dto.ts +0 -13
- package/src/common/dto/create-translation.dto.ts +0 -10
- package/src/common/dto/index.ts +0 -6
- package/src/common/dto/page-meta.dto.ts +0 -37
- package/src/common/dto/page-options.dto.ts +0 -35
- package/src/common/dto/page.dto.ts +0 -36
- package/src/common/index.ts +0 -7
- package/src/common/snake-naming.strategy.ts +0 -64
- package/src/common/types.ts +0 -44
- package/src/common/utils.ts +0 -45
- package/src/constants/index.ts +0 -2
- package/src/constants/language-code.ts +0 -7
- package/src/constants/order.ts +0 -4
- package/src/decorators/api-page-ok-response.decorator.ts +0 -32
- package/src/decorators/auth-user.decorator.ts +0 -16
- package/src/decorators/controller.decorator.ts +0 -8
- package/src/decorators/field.decorators.ts +0 -856
- package/src/decorators/http.decorators.ts +0 -10
- package/src/decorators/index.ts +0 -12
- 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.ts +0 -159
- package/src/decorators/translate.decorator.ts +0 -19
- package/src/decorators/use-dto.decorator.ts +0 -11
- package/src/decorators/user-check.decorator.ts +0 -30
- package/src/decorators/user.decorator.ts +0 -59
- package/src/decorators/user_auth.decorator.ts +0 -15
- package/src/decorators/validator.decorators.ts +0 -98
- 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.ts +0 -77
- package/src/filters/constraint-errors.ts +0 -5
- package/src/filters/index.ts +0 -3
- package/src/filters/query-failed.filter.ts +0 -32
- package/src/health-checker/health-checker.controller.ts +0 -51
- package/src/health-checker/health-checker.module.ts +0 -13
- package/src/health-checker/health-indicators/service.indicator.ts +0 -44
- package/src/helpers/common.helper.ts +0 -49
- package/src/helpers/date.helper.ts +0 -64
- package/src/helpers/index.ts +0 -2
- package/src/i18n/en_US/validation.json +0 -41
- package/src/i18n/zh_CN/validation.json +0 -41
- package/src/index.ts +0 -11
- package/src/interceptors/index.ts +0 -2
- package/src/interceptors/language-interceptor.service.ts +0 -28
- 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 -4
- 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/middlewares/xml.middleware.ts +0 -14
- package/src/providers/context.provider.ts +0 -109
- package/src/providers/generator.provider.ts +0 -66
- package/src/providers/index.ts +0 -2
- package/src/setup/bootstrap.setup.ts +0 -254
- package/src/setup/index.ts +0 -1
- package/src/shared/index.ts +0 -2
- package/src/shared/serviceRegistryModule.ts +0 -135
- package/src/shared/services/api-config.service.ts +0 -336
- package/src/shared/services/generator.service.ts +0 -13
- package/src/shared/services/index.ts +0 -4
- package/src/shared/services/translation.service.ts +0 -59
- package/src/shared/services/validator.service.ts +0 -10
- package/src/validator-json/decorators.ts +0 -63
- package/src/validator-json/default.ts +0 -257
- package/src/validator-json/defaultConverters.ts +0 -402
- package/src/validator-json/index.ts +0 -4
- package/src/validator-json/options.ts +0 -50
- package/src/validators/file-mimetype.validator.ts +0 -34
- package/src/validators/index.ts +0 -6
- package/src/validators/is-exists.validator.ts +0 -60
- 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 -31
- package/tsconfig.lib.json +0 -16
- /package/{dist/.hygen → .hygen}/new/crud/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create-command.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/get-query.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/module/repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{dist/.hygen.js → .hygen.js} +0 -0
- /package/{dist/common → common}/abstract-client.service.d.ts +0 -0
- /package/{dist/common → common}/abstract-client.service.js +0 -0
- /package/{dist/common → common}/abstract.entity.d.ts +0 -0
- /package/{dist/common → common}/abstract.entity.js +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.d.ts +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.js +0 -0
- /package/{dist/common → common}/dto/abstract.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/abstract.dto.js +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.js +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.js +0 -0
- /package/{dist/common → common}/dto/index.d.ts +0 -0
- /package/{dist/common → common}/dto/index.js +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.js +0 -0
- /package/{dist/common → common}/dto/page-options.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-options.dto.js +0 -0
- /package/{dist/common → common}/dto/page.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page.dto.js +0 -0
- /package/{dist/common → common}/index.d.ts +0 -0
- /package/{dist/common → common}/index.js +0 -0
- /package/{dist/common → common}/snake-naming.strategy.d.ts +0 -0
- /package/{dist/common → common}/snake-naming.strategy.js +0 -0
- /package/{dist/common → common}/types.d.ts +0 -0
- /package/{dist/common → common}/types.js +0 -0
- /package/{dist/common → common}/utils.d.ts +0 -0
- /package/{dist/common → common}/utils.js +0 -0
- /package/{dist/constants → constants}/index.d.ts +0 -0
- /package/{dist/constants → constants}/index.js +0 -0
- /package/{dist/constants → constants}/language-code.d.ts +0 -0
- /package/{dist/constants → constants}/language-code.js +0 -0
- /package/{dist/constants → constants}/order.d.ts +0 -0
- /package/{dist/constants → constants}/order.js +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.js +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.js +0 -0
- /package/{dist/decorators → decorators}/field.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/field.decorators.js +0 -0
- /package/{dist/decorators → decorators}/http.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/http.decorators.js +0 -0
- /package/{dist/decorators → decorators}/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/index.js +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.js +0 -0
- /package/{dist/decorators → decorators}/property.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/property.decorators.js +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.js +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.d.ts +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.js +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.js +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.js +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.js +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.js +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.js +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/index.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/index.js +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.js +0 -0
- /package/{dist/filters → filters}/bad-request.filter.d.ts +0 -0
- /package/{dist/filters → filters}/bad-request.filter.js +0 -0
- /package/{dist/filters → filters}/constraint-errors.d.ts +0 -0
- /package/{dist/filters → filters}/constraint-errors.js +0 -0
- /package/{dist/filters → filters}/index.d.ts +0 -0
- /package/{dist/filters → filters}/index.js +0 -0
- /package/{dist/filters → filters}/query-failed.filter.d.ts +0 -0
- /package/{dist/filters → filters}/query-failed.filter.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.js +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{dist/helpers → helpers}/common.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/common.helper.js +0 -0
- /package/{dist/helpers → helpers}/date.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/date.helper.js +0 -0
- /package/{dist/helpers → helpers}/index.d.ts +0 -0
- /package/{dist/helpers → helpers}/index.js +0 -0
- /package/{dist/i18n → i18n}/en_US/validation.json +0 -0
- /package/{dist/i18n → i18n}/zh_CN/validation.json +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/interceptors → interceptors}/index.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/index.js +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.js +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.js +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.js +0 -0
- /package/{dist/interfaces → interfaces}/IFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IFile.js +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{dist/interfaces → interfaces}/index.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/index.js +0 -0
- /package/{dist/interfaces → interfaces}/response.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/response.js +0 -0
- /package/{dist/middlewares → middlewares}/index.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/index.js +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.js +0 -0
- /package/{dist/providers → providers}/context.provider.d.ts +0 -0
- /package/{dist/providers → providers}/context.provider.js +0 -0
- /package/{dist/providers → providers}/generator.provider.d.ts +0 -0
- /package/{dist/providers → providers}/generator.provider.js +0 -0
- /package/{dist/providers → providers}/index.d.ts +0 -0
- /package/{dist/providers → providers}/index.js +0 -0
- /package/{dist/setup → setup}/bootstrap.setup.d.ts +0 -0
- /package/{dist/setup → setup}/bootstrap.setup.js +0 -0
- /package/{dist/setup → setup}/index.d.ts +0 -0
- /package/{dist/setup → setup}/index.js +0 -0
- /package/{dist/shared → shared}/index.d.ts +0 -0
- /package/{dist/shared → shared}/index.js +0 -0
- /package/{dist/shared → shared}/serviceRegistryModule.d.ts +0 -0
- /package/{dist/shared → shared}/serviceRegistryModule.js +0 -0
- /package/{dist/shared → shared}/services/api-config.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/api-config.service.js +0 -0
- /package/{dist/shared → shared}/services/generator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/generator.service.js +0 -0
- /package/{dist/shared → shared}/services/index.d.ts +0 -0
- /package/{dist/shared → shared}/services/index.js +0 -0
- /package/{dist/shared → shared}/services/translation.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/translation.service.js +0 -0
- /package/{dist/shared → shared}/services/validator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/validator.service.js +0 -0
- /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
- /package/{dist/validator-json → validator-json}/decorators.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/decorators.js +0 -0
- /package/{dist/validator-json → validator-json}/default.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/default.js +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.js +0 -0
- /package/{dist/validator-json → validator-json}/index.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/index.js +0 -0
- /package/{dist/validator-json → validator-json}/options.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/options.js +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.d.ts +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.js +0 -0
- /package/{dist/validators → validators}/index.d.ts +0 -0
- /package/{dist/validators → validators}/index.js +0 -0
- /package/{dist/validators → validators}/is-exists.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-exists.validator.js +0 -0
- /package/{dist/validators → validators}/is-unique.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-unique.validator.js +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.d.ts +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.js +0 -0
- /package/{dist/validators → validators}/same-as.validator.d.ts +0 -0
- /package/{dist/validators → validators}/same-as.validator.js +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.d.ts +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.js +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { FileValidator } from '@nestjs/common/pipes/file/file-validator.interface';
|
|
2
|
-
import { IFile } from '@nestjs/common/pipes/file/interfaces';
|
|
3
|
-
|
|
4
|
-
export type FileMimetypeValidatorOptions = {
|
|
5
|
-
allowedMimetypes: string[];
|
|
6
|
-
message?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export class FileMimetypeValidator extends FileValidator<
|
|
10
|
-
FileMimetypeValidatorOptions,
|
|
11
|
-
IFile
|
|
12
|
-
> {
|
|
13
|
-
private allowedMimetypes: string[];
|
|
14
|
-
private message: string;
|
|
15
|
-
|
|
16
|
-
constructor(options: FileMimetypeValidatorOptions) {
|
|
17
|
-
super(options);
|
|
18
|
-
this.allowedMimetypes = options.allowedMimetypes;
|
|
19
|
-
this.message = options.message;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
buildErrorMessage(): string {
|
|
23
|
-
if (this.message) {
|
|
24
|
-
return this.message;
|
|
25
|
-
}
|
|
26
|
-
return `Invalid file type. Only ${this.allowedMimetypes.join(
|
|
27
|
-
', ',
|
|
28
|
-
)} are allowed.`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
isValid(file?: IFile): boolean {
|
|
32
|
-
return this.allowedMimetypes.includes(file.mimetype);
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/validators/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ValidationArguments,
|
|
3
|
-
ValidationOptions,
|
|
4
|
-
ValidatorConstraintInterface,
|
|
5
|
-
} from 'class-validator';
|
|
6
|
-
import { registerDecorator, ValidatorConstraint } from 'class-validator';
|
|
7
|
-
import type { EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
|
|
8
|
-
import { DataSource } from 'typeorm';
|
|
9
|
-
import { getDataSourceByName } from 'typeorm-transactional';
|
|
10
|
-
import { i18nValidationMessage } from 'nestjs-i18n';
|
|
11
|
-
import { Injectable } from '@nestjs/common';
|
|
12
|
-
|
|
13
|
-
@Injectable()
|
|
14
|
-
@ValidatorConstraint({ name: 'isExists', async: true })
|
|
15
|
-
export class IsExistsValidator implements ValidatorConstraintInterface {
|
|
16
|
-
constructor(private readonly dataSource: DataSource) {
|
|
17
|
-
this.dataSource = getDataSourceByName('default');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async validate<E>(
|
|
21
|
-
value: string,
|
|
22
|
-
args: IExistsValidationArguments<E>,
|
|
23
|
-
): Promise<boolean> {
|
|
24
|
-
const [entityClass, findCondition] = args.constraints;
|
|
25
|
-
args.value = value;
|
|
26
|
-
return (
|
|
27
|
-
(await this.dataSource.getRepository(entityClass).count({
|
|
28
|
-
where: findCondition(args),
|
|
29
|
-
})) > 0
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
defaultMessage(args: ValidationArguments): string {
|
|
34
|
-
return i18nValidationMessage('validation.IS_EXISTS')(args);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ExistsValidationConstraints<E> = [
|
|
39
|
-
ObjectType<E> | EntitySchema<E> | string,
|
|
40
|
-
(validationArguments: ValidationArguments) => FindOptionsWhere<E>,
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
interface IExistsValidationArguments<E> extends ValidationArguments {
|
|
44
|
-
constraints: ExistsValidationConstraints<E>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function IsExists<E>(
|
|
48
|
-
constraints: Partial<ExistsValidationConstraints<E>>,
|
|
49
|
-
validationOptions?: ValidationOptions,
|
|
50
|
-
): PropertyDecorator {
|
|
51
|
-
return (object, propertyName: string) => {
|
|
52
|
-
registerDecorator({
|
|
53
|
-
target: object.constructor,
|
|
54
|
-
propertyName,
|
|
55
|
-
options: validationOptions,
|
|
56
|
-
constraints,
|
|
57
|
-
validator: IsExistsValidator,
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ValidationArguments,
|
|
3
|
-
ValidationOptions,
|
|
4
|
-
ValidatorConstraintInterface,
|
|
5
|
-
} from 'class-validator';
|
|
6
|
-
import { registerDecorator, ValidatorConstraint } from 'class-validator';
|
|
7
|
-
import {
|
|
8
|
-
DataSource,
|
|
9
|
-
EntitySchema,
|
|
10
|
-
FindOptionsWhere,
|
|
11
|
-
ObjectType,
|
|
12
|
-
} from 'typeorm';
|
|
13
|
-
import { getDataSourceByName } from 'typeorm-transactional';
|
|
14
|
-
import { i18nValidationMessage } from 'nestjs-i18n';
|
|
15
|
-
|
|
16
|
-
@ValidatorConstraint({ name: 'isUnique', async: true })
|
|
17
|
-
export class IsUniqueValidator implements ValidatorConstraintInterface {
|
|
18
|
-
constructor(private readonly dataSource: DataSource) {
|
|
19
|
-
this.dataSource = getDataSourceByName('default');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public async validate<E>(
|
|
23
|
-
value: string,
|
|
24
|
-
args: IUniqueValidationArguments<E>,
|
|
25
|
-
): Promise<boolean> {
|
|
26
|
-
const [entityClass, findCondition] = args.constraints;
|
|
27
|
-
args.value = value;
|
|
28
|
-
let exists: boolean;
|
|
29
|
-
const defCon = findCondition(args);
|
|
30
|
-
const pkCols = this.dataSource
|
|
31
|
-
.getMetadata(entityClass)
|
|
32
|
-
.primaryColumns.map((column) => column.propertyName);
|
|
33
|
-
|
|
34
|
-
const isNew = pkCols.some((pk) => args.object[pk]);
|
|
35
|
-
if (!isNew) {
|
|
36
|
-
exists =
|
|
37
|
-
(await this.dataSource
|
|
38
|
-
.getRepository(entityClass)
|
|
39
|
-
.count({ where: defCon })) < 1;
|
|
40
|
-
} else {
|
|
41
|
-
const entities = await this.dataSource
|
|
42
|
-
.getRepository(entityClass)
|
|
43
|
-
.createQueryBuilder()
|
|
44
|
-
.where(defCon)
|
|
45
|
-
.select(pkCols)
|
|
46
|
-
.limit(2)
|
|
47
|
-
.execute();
|
|
48
|
-
|
|
49
|
-
const entityCount = entities.length;
|
|
50
|
-
if (entityCount === 1) {
|
|
51
|
-
const entity = entities[0];
|
|
52
|
-
const oldPk = {};
|
|
53
|
-
const newPk = {};
|
|
54
|
-
pkCols.map((pk) => {
|
|
55
|
-
oldPk[pk] = entity[pk];
|
|
56
|
-
newPk[pk] = args.object[pk];
|
|
57
|
-
});
|
|
58
|
-
exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
|
|
59
|
-
} else {
|
|
60
|
-
exists = entityCount < 1;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return exists;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
defaultMessage(args: ValidationArguments): string {
|
|
67
|
-
return i18nValidationMessage('validation.IS_UNIQUE')(args);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type UniqueValidationConstraints<E> = [
|
|
72
|
-
ObjectType<E> | EntitySchema<E> | string,
|
|
73
|
-
(validationArguments: ValidationArguments) => FindOptionsWhere<E>,
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
interface IUniqueValidationArguments<E> extends ValidationArguments {
|
|
77
|
-
constraints: UniqueValidationConstraints<E>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function IsUnique<E>(
|
|
81
|
-
constraints: Partial<UniqueValidationConstraints<E>>,
|
|
82
|
-
validationOptions?: ValidationOptions,
|
|
83
|
-
): PropertyDecorator {
|
|
84
|
-
return function (object, propertyName: string) {
|
|
85
|
-
registerDecorator({
|
|
86
|
-
target: object.constructor,
|
|
87
|
-
propertyName,
|
|
88
|
-
options: validationOptions,
|
|
89
|
-
constraints,
|
|
90
|
-
validator: IsUniqueValidator,
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isPhoneNumber,
|
|
3
|
-
registerDecorator,
|
|
4
|
-
ValidateIf,
|
|
5
|
-
ValidationArguments,
|
|
6
|
-
ValidationOptions,
|
|
7
|
-
} from 'class-validator';
|
|
8
|
-
|
|
9
|
-
export function IsPhoneNumberWithCountryCode(
|
|
10
|
-
validationOptions?: ValidationOptions,
|
|
11
|
-
) {
|
|
12
|
-
return function (object: NonNullable<unknown>, propertyName: string) {
|
|
13
|
-
ValidateIf((_, value) => !!value)(object, propertyName);
|
|
14
|
-
const countryCodePropertyName = 'countryCode';
|
|
15
|
-
|
|
16
|
-
registerDecorator({
|
|
17
|
-
name: 'isPhoneNumberWithCountryCode',
|
|
18
|
-
target: object.constructor,
|
|
19
|
-
propertyName: propertyName,
|
|
20
|
-
constraints: [countryCodePropertyName],
|
|
21
|
-
options: validationOptions,
|
|
22
|
-
validator: {
|
|
23
|
-
validate(value: any, args: ValidationArguments) {
|
|
24
|
-
const [countryCodePropertyName] = args.constraints;
|
|
25
|
-
const countryCode = args.object[countryCodePropertyName];
|
|
26
|
-
return isPhoneNumber(value, countryCode);
|
|
27
|
-
},
|
|
28
|
-
defaultMessage(args: ValidationArguments) {
|
|
29
|
-
const [countryCodePropertyName] = args.constraints;
|
|
30
|
-
const countryCode = args.object[countryCodePropertyName];
|
|
31
|
-
return `$property must be a valid phone number in the country code ${countryCode}`;
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ValidationOptions } from 'class-validator';
|
|
2
|
-
import { registerDecorator } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export function SameAs(
|
|
5
|
-
property: string,
|
|
6
|
-
validationOptions?: ValidationOptions,
|
|
7
|
-
): PropertyDecorator {
|
|
8
|
-
return function (object, propertyName: string) {
|
|
9
|
-
registerDecorator({
|
|
10
|
-
name: 'sameAs',
|
|
11
|
-
target: object.constructor,
|
|
12
|
-
propertyName,
|
|
13
|
-
options: validationOptions,
|
|
14
|
-
constraints: [property],
|
|
15
|
-
validator: {
|
|
16
|
-
validate(value, args) {
|
|
17
|
-
const [relatedPropertyName] = args!.constraints;
|
|
18
|
-
|
|
19
|
-
return args?.object[relatedPropertyName] === value;
|
|
20
|
-
},
|
|
21
|
-
defaultMessage() {
|
|
22
|
-
return '$property must match $constraint1';
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { applyDecorators } from '@nestjs/common';
|
|
2
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
-
import { ValidateIf } from 'class-validator';
|
|
4
|
-
import { isString } from 'lodash';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* When the value is emtpy, validation is skipped
|
|
8
|
-
* @param field
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
export function SkipEmpty(field?: string) {
|
|
12
|
-
return applyDecorators(
|
|
13
|
-
ApiProperty({ required: false }),
|
|
14
|
-
ValidateIf((obj, value) => {
|
|
15
|
-
if (field) {
|
|
16
|
-
value = obj[field];
|
|
17
|
-
}
|
|
18
|
-
return !(
|
|
19
|
-
value === null ||
|
|
20
|
-
value === undefined ||
|
|
21
|
-
(isString(value) && value.trim() === '')
|
|
22
|
-
);
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"removeComments": true,
|
|
6
|
-
"emitDecoratorMetadata": true,
|
|
7
|
-
"experimentalDecorators": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"target": "es6",
|
|
10
|
-
"sourceMap": false,
|
|
11
|
-
"outDir": "./dist",
|
|
12
|
-
"baseUrl": "./dist",
|
|
13
|
-
"incremental": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"strictNullChecks": false,
|
|
16
|
-
"noImplicitAny": false,
|
|
17
|
-
"strictBindCallApply": false,
|
|
18
|
-
"forceConsistentCasingInFileNames": false,
|
|
19
|
-
"noFallthroughCasesInSwitch": false,
|
|
20
|
-
"resolveJsonModule": true
|
|
21
|
-
},
|
|
22
|
-
"include": [
|
|
23
|
-
"./src/**/*.ts",
|
|
24
|
-
"./src/i18n/**/*.json"
|
|
25
|
-
],
|
|
26
|
-
"exclude": [
|
|
27
|
-
"node_modules",
|
|
28
|
-
"**/*.spec.ts",
|
|
29
|
-
"tests"
|
|
30
|
-
]
|
|
31
|
-
}
|
package/tsconfig.lib.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|