@nest-omni/core 1.0.56 → 2.0.1-0
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/.history/src/common/boilerplate.polyfill_20250521135408.ts +202 -0
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +291 -0
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +317 -0
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +319 -0
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +289 -0
- package/README.md +16 -0
- package/build.sh +45 -0
- package/{common → dist/common}/abstract.entity.d.ts +1 -0
- package/{common → dist/common}/abstract.entity.js +13 -0
- package/{decorators → dist/decorators}/field.decorators.d.ts +1 -1
- package/dist/package.json +71 -0
- package/{providers → dist/providers}/context.provider.d.ts +3 -3
- package/dist/setup/bootstrap.setup.d.ts +2 -0
- package/{setup → dist/setup}/bootstrap.setup.js +45 -27
- package/{shared → dist/shared}/serviceRegistryModule.js +4 -11
- package/{shared → dist/shared}/services/api-config.service.d.ts +3 -15
- package/{shared → dist/shared}/services/api-config.service.js +15 -42
- package/{shared → dist/shared}/services/index.d.ts +0 -1
- package/{shared → dist/shared}/services/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/yarn.lock +644 -0
- package/package.json +1 -3
- package/src/.hygen.js +116 -0
- package/src/common/abstract-client.service.ts +56 -0
- package/src/common/abstract.entity.ts +82 -0
- package/src/common/boilerplate.polyfill.ts +202 -0
- package/src/common/dto/abstract.dto.ts +61 -0
- package/src/common/dto/bulk-id.dto.ts +13 -0
- package/src/common/dto/create-translation.dto.ts +10 -0
- package/src/common/dto/index.ts +6 -0
- package/src/common/dto/page-meta.dto.ts +37 -0
- package/src/common/dto/page-options.dto.ts +35 -0
- package/src/common/dto/page.dto.ts +36 -0
- package/src/common/index.ts +7 -0
- package/src/common/snake-naming.strategy.ts +64 -0
- package/src/common/types.ts +44 -0
- package/src/common/utils.ts +45 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/language-code.ts +7 -0
- package/src/constants/order.ts +4 -0
- package/src/decorators/api-page-ok-response.decorator.ts +32 -0
- package/src/decorators/auth-user.decorator.ts +16 -0
- package/src/decorators/controller.decorator.ts +8 -0
- package/src/decorators/field.decorators.ts +856 -0
- package/src/decorators/http.decorators.ts +10 -0
- package/src/decorators/index.ts +12 -0
- package/src/decorators/operation.decorator.ts +4 -0
- package/src/decorators/property.decorators.ts +62 -0
- package/src/decorators/public-route.decorator.ts +8 -0
- package/src/decorators/swagger.schema.ts +117 -0
- package/src/decorators/timestamp-column.decorator.ts +29 -0
- package/src/decorators/transform.decorators.ts +159 -0
- package/src/decorators/translate.decorator.ts +19 -0
- package/src/decorators/use-dto.decorator.ts +11 -0
- package/src/decorators/user-check.decorator.ts +30 -0
- package/src/decorators/user.decorator.ts +59 -0
- package/src/decorators/user_auth.decorator.ts +15 -0
- package/src/decorators/validator.decorators.ts +98 -0
- package/src/exceptions/file-not-image.exception.ts +7 -0
- package/src/exceptions/index.ts +2 -0
- package/src/exceptions/page-type.exception.ts +7 -0
- package/src/exceptions/user-not-found.exception.ts +7 -0
- package/src/filters/bad-request.filter.ts +77 -0
- package/src/filters/constraint-errors.ts +5 -0
- package/src/filters/index.ts +3 -0
- package/src/filters/query-failed.filter.ts +32 -0
- package/src/health-checker/health-checker.controller.ts +51 -0
- package/src/health-checker/health-checker.module.ts +13 -0
- package/src/health-checker/health-indicators/service.indicator.ts +44 -0
- package/src/helpers/common.helper.ts +49 -0
- package/src/helpers/date.helper.ts +64 -0
- package/src/helpers/index.ts +2 -0
- package/src/i18n/en_US/validation.json +41 -0
- package/src/i18n/zh_CN/validation.json +41 -0
- package/src/index.ts +11 -0
- package/src/interceptors/index.ts +2 -0
- package/src/interceptors/language-interceptor.service.ts +28 -0
- package/src/interceptors/translation-interceptor.service.ts +43 -0
- package/src/interfaces/IApiFile.ts +4 -0
- package/src/interfaces/IFile.ts +8 -0
- package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/response.ts +37 -0
- package/src/middlewares/index.ts +4 -0
- package/src/middlewares/omni-auth.middleware.ts +10 -0
- package/src/middlewares/powerby.middleware.ts +6 -0
- package/src/middlewares/request-id.middleware.ts +28 -0
- package/src/middlewares/xml.middleware.ts +14 -0
- package/src/providers/context.provider.ts +109 -0
- package/src/providers/generator.provider.ts +66 -0
- package/src/providers/index.ts +2 -0
- package/src/setup/bootstrap.setup.ts +254 -0
- package/src/setup/index.ts +1 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/serviceRegistryModule.ts +135 -0
- package/src/shared/services/api-config.service.ts +336 -0
- package/src/shared/services/generator.service.ts +13 -0
- package/src/shared/services/index.ts +4 -0
- package/src/shared/services/translation.service.ts +59 -0
- package/src/shared/services/validator.service.ts +10 -0
- package/src/validator-json/decorators.ts +63 -0
- package/src/validator-json/default.ts +257 -0
- package/src/validator-json/defaultConverters.ts +402 -0
- package/src/validator-json/index.ts +4 -0
- package/src/validator-json/options.ts +50 -0
- package/src/validators/file-mimetype.validator.ts +34 -0
- package/src/validators/index.ts +6 -0
- package/src/validators/is-exists.validator.ts +60 -0
- package/src/validators/is-unique.validator.ts +93 -0
- package/src/validators/phone-country-code.validator.ts +36 -0
- package/src/validators/same-as.validator.ts +27 -0
- package/src/validators/skip-empty.validator.ts +25 -0
- package/tsconfig.json +31 -0
- package/tsconfig.lib.json +16 -0
- package/setup/bootstrap.setup.d.ts +0 -2
- package/shared/services/aws-s3.service.d.ts +0 -10
- package/shared/services/aws-s3.service.js +0 -56
- package/tsconfig.tsbuildinfo +0 -1
- /package/{.hygen → dist/.hygen}/new/crud/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create-command.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/get-query.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/module/repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{.hygen.js → dist/.hygen.js} +0 -0
- /package/{common → dist/common}/abstract-client.service.d.ts +0 -0
- /package/{common → dist/common}/abstract-client.service.js +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.d.ts +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.js +0 -0
- /package/{common → dist/common}/dto/abstract.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/abstract.dto.js +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.js +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.js +0 -0
- /package/{common → dist/common}/dto/index.d.ts +0 -0
- /package/{common → dist/common}/dto/index.js +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.js +0 -0
- /package/{common → dist/common}/dto/page-options.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-options.dto.js +0 -0
- /package/{common → dist/common}/dto/page.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page.dto.js +0 -0
- /package/{common → dist/common}/index.d.ts +0 -0
- /package/{common → dist/common}/index.js +0 -0
- /package/{common → dist/common}/snake-naming.strategy.d.ts +0 -0
- /package/{common → dist/common}/snake-naming.strategy.js +0 -0
- /package/{common → dist/common}/types.d.ts +0 -0
- /package/{common → dist/common}/types.js +0 -0
- /package/{common → dist/common}/utils.d.ts +0 -0
- /package/{common → dist/common}/utils.js +0 -0
- /package/{constants → dist/constants}/index.d.ts +0 -0
- /package/{constants → dist/constants}/index.js +0 -0
- /package/{constants → dist/constants}/language-code.d.ts +0 -0
- /package/{constants → dist/constants}/language-code.js +0 -0
- /package/{constants → dist/constants}/order.d.ts +0 -0
- /package/{constants → dist/constants}/order.js +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.js +0 -0
- /package/{decorators → dist/decorators}/field.decorators.js +0 -0
- /package/{decorators → dist/decorators}/http.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/http.decorators.js +0 -0
- /package/{decorators → dist/decorators}/index.d.ts +0 -0
- /package/{decorators → dist/decorators}/index.js +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.js +0 -0
- /package/{decorators → dist/decorators}/property.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/property.decorators.js +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.js +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.d.ts +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.js +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.js +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.js +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.js +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.js +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.js +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/index.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/index.js +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.js +0 -0
- /package/{filters → dist/filters}/bad-request.filter.d.ts +0 -0
- /package/{filters → dist/filters}/bad-request.filter.js +0 -0
- /package/{filters → dist/filters}/constraint-errors.d.ts +0 -0
- /package/{filters → dist/filters}/constraint-errors.js +0 -0
- /package/{filters → dist/filters}/index.d.ts +0 -0
- /package/{filters → dist/filters}/index.js +0 -0
- /package/{filters → dist/filters}/query-failed.filter.d.ts +0 -0
- /package/{filters → dist/filters}/query-failed.filter.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.js +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{helpers → dist/helpers}/common.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/common.helper.js +0 -0
- /package/{helpers → dist/helpers}/date.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/date.helper.js +0 -0
- /package/{helpers → dist/helpers}/index.d.ts +0 -0
- /package/{helpers → dist/helpers}/index.js +0 -0
- /package/{i18n → dist/i18n}/en_US/validation.json +0 -0
- /package/{i18n → dist/i18n}/zh_CN/validation.json +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{interceptors → dist/interceptors}/index.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/index.js +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.js +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.js +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.js +0 -0
- /package/{interfaces → dist/interfaces}/IFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IFile.js +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{interfaces → dist/interfaces}/index.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/index.js +0 -0
- /package/{interfaces → dist/interfaces}/response.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/response.js +0 -0
- /package/{middlewares → dist/middlewares}/index.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/index.js +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.js +0 -0
- /package/{providers → dist/providers}/context.provider.js +0 -0
- /package/{providers → dist/providers}/generator.provider.d.ts +0 -0
- /package/{providers → dist/providers}/generator.provider.js +0 -0
- /package/{providers → dist/providers}/index.d.ts +0 -0
- /package/{providers → dist/providers}/index.js +0 -0
- /package/{setup → dist/setup}/index.d.ts +0 -0
- /package/{setup → dist/setup}/index.js +0 -0
- /package/{shared → dist/shared}/index.d.ts +0 -0
- /package/{shared → dist/shared}/index.js +0 -0
- /package/{shared → dist/shared}/serviceRegistryModule.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.js +0 -0
- /package/{shared → dist/shared}/services/translation.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/translation.service.js +0 -0
- /package/{shared → dist/shared}/services/validator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/validator.service.js +0 -0
- /package/{validator-json → dist/validator-json}/decorators.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/decorators.js +0 -0
- /package/{validator-json → dist/validator-json}/default.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/default.js +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.js +0 -0
- /package/{validator-json → dist/validator-json}/index.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/index.js +0 -0
- /package/{validator-json → dist/validator-json}/options.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/options.js +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.d.ts +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.js +0 -0
- /package/{validators → dist/validators}/index.d.ts +0 -0
- /package/{validators → dist/validators}/index.js +0 -0
- /package/{validators → dist/validators}/is-exists.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-exists.validator.js +0 -0
- /package/{validators → dist/validators}/is-unique.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-unique.validator.js +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.d.ts +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.js +0 -0
- /package/{validators → dist/validators}/same-as.validator.d.ts +0 -0
- /package/{validators → dist/validators}/same-as.validator.js +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.d.ts +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.js +0 -0
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
import { applyDecorators } from '@nestjs/common';
|
|
2
|
+
import type { ApiPropertyOptions } from '@nestjs/swagger';
|
|
3
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
4
|
+
import { i18nValidationMessage } from 'nestjs-i18n';
|
|
5
|
+
import { Type } from 'class-transformer';
|
|
6
|
+
import {
|
|
7
|
+
ArrayMaxSize,
|
|
8
|
+
ArrayMinSize,
|
|
9
|
+
IsBoolean,
|
|
10
|
+
IsDate,
|
|
11
|
+
IsDefined,
|
|
12
|
+
IsEmail,
|
|
13
|
+
IsEnum,
|
|
14
|
+
IsFQDN,
|
|
15
|
+
IsInt,
|
|
16
|
+
IsIP,
|
|
17
|
+
IsLocale,
|
|
18
|
+
IsNumber,
|
|
19
|
+
IsObject,
|
|
20
|
+
IsPositive,
|
|
21
|
+
IsString,
|
|
22
|
+
IsTimeZone,
|
|
23
|
+
IsUrl,
|
|
24
|
+
IsUUID,
|
|
25
|
+
Max,
|
|
26
|
+
MaxDate,
|
|
27
|
+
MaxLength,
|
|
28
|
+
Min,
|
|
29
|
+
MinDate,
|
|
30
|
+
MinLength,
|
|
31
|
+
NotEquals,
|
|
32
|
+
ValidateNested,
|
|
33
|
+
} from 'class-validator';
|
|
34
|
+
|
|
35
|
+
import { supportedLanguageCount } from '../constants';
|
|
36
|
+
import { ApiEnumProperty, ApiUUIDProperty } from './property.decorators';
|
|
37
|
+
import {
|
|
38
|
+
PhoneNumberSerializer,
|
|
39
|
+
ToArray,
|
|
40
|
+
ToBoolean,
|
|
41
|
+
ToLowerCase,
|
|
42
|
+
ToUpperCase,
|
|
43
|
+
} from './transform.decorators';
|
|
44
|
+
import {
|
|
45
|
+
IsEmptyable,
|
|
46
|
+
IsHttpUrl,
|
|
47
|
+
IsNullable,
|
|
48
|
+
IsPhoneNumber,
|
|
49
|
+
IsTmpKey as IsTemporaryKey,
|
|
50
|
+
} from './validator.decorators';
|
|
51
|
+
import * as ValidatorJS from 'validator';
|
|
52
|
+
|
|
53
|
+
type RequireField<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
54
|
+
|
|
55
|
+
interface IFieldOptions {
|
|
56
|
+
each?: boolean;
|
|
57
|
+
swagger?: boolean;
|
|
58
|
+
nullable?: boolean;
|
|
59
|
+
group?: string[];
|
|
60
|
+
message?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface INumberFieldOptions extends IFieldOptions {
|
|
64
|
+
min?: number;
|
|
65
|
+
max?: number;
|
|
66
|
+
int?: boolean;
|
|
67
|
+
isPositive?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface IDateFieldOptions extends IFieldOptions {
|
|
71
|
+
minDate?: Date | (() => Date);
|
|
72
|
+
maxDate?: Date | (() => Date);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface IStringFieldOptions extends IFieldOptions {
|
|
76
|
+
minLength?: number;
|
|
77
|
+
maxLength?: number;
|
|
78
|
+
toLowerCase?: boolean;
|
|
79
|
+
toUpperCase?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface IEmailFieldOptions {
|
|
83
|
+
emailOptions?: ValidatorJS.IsEmailOptions;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface IIPFieldOptions {
|
|
87
|
+
version?: ValidatorJS.IPVersion;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface IURLFieldOptions {
|
|
91
|
+
urlOptions?: ValidatorJS.IsURLOptions;
|
|
92
|
+
simpleUrl?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface IFQDNFieldOptions extends ValidatorJS.IsFQDNOptions {}
|
|
96
|
+
|
|
97
|
+
type IClassFieldOptions = IFieldOptions;
|
|
98
|
+
type IBooleanFieldOptions = IFieldOptions;
|
|
99
|
+
type IEnumFieldOptions = IFieldOptions;
|
|
100
|
+
|
|
101
|
+
export function NumberField(
|
|
102
|
+
options: Omit<ApiPropertyOptions, 'type'> & INumberFieldOptions = {},
|
|
103
|
+
): PropertyDecorator {
|
|
104
|
+
const decorators = [Type(() => Number)];
|
|
105
|
+
|
|
106
|
+
if (options.nullable) {
|
|
107
|
+
decorators.push(
|
|
108
|
+
IsNullable({
|
|
109
|
+
each: options.each,
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
} else {
|
|
113
|
+
decorators.push(
|
|
114
|
+
NotEquals(null, {
|
|
115
|
+
each: options.each,
|
|
116
|
+
message: i18nValidationMessage('validation.NOT_EQUALS'),
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (options.swagger !== false) {
|
|
122
|
+
decorators.push(ApiProperty({ type: Number, ...options }));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (options.each) {
|
|
126
|
+
decorators.push(ToArray());
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (options.int) {
|
|
130
|
+
decorators.push(
|
|
131
|
+
IsInt({
|
|
132
|
+
each: options.each,
|
|
133
|
+
message: i18nValidationMessage('validation.IS_INT'),
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
decorators.push(
|
|
138
|
+
IsNumber(
|
|
139
|
+
{},
|
|
140
|
+
{
|
|
141
|
+
each: options.each,
|
|
142
|
+
message: i18nValidationMessage('validation.IS_NUMBER'),
|
|
143
|
+
},
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (typeof options.min === 'number') {
|
|
149
|
+
decorators.push(
|
|
150
|
+
Min(options.min, {
|
|
151
|
+
each: options.each,
|
|
152
|
+
message: i18nValidationMessage('validation.MIN'),
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (typeof options.max === 'number') {
|
|
158
|
+
decorators.push(
|
|
159
|
+
Max(options.max, {
|
|
160
|
+
each: options.each,
|
|
161
|
+
message: i18nValidationMessage('validation.MAX'),
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (options.isPositive) {
|
|
167
|
+
decorators.push(
|
|
168
|
+
IsPositive({
|
|
169
|
+
each: options.each,
|
|
170
|
+
message: i18nValidationMessage('validation.IS_POSITIVE'),
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return applyDecorators(...decorators);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function NumberFieldOptional(
|
|
179
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
180
|
+
INumberFieldOptions = {},
|
|
181
|
+
): PropertyDecorator {
|
|
182
|
+
return applyDecorators(
|
|
183
|
+
IsEmptyable(),
|
|
184
|
+
NumberField({ required: false, ...options }),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function StringField(
|
|
189
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
190
|
+
): PropertyDecorator {
|
|
191
|
+
const decorators = [
|
|
192
|
+
Type(() => String),
|
|
193
|
+
IsString({
|
|
194
|
+
each: options.each,
|
|
195
|
+
message: i18nValidationMessage('validation.IS_STRING'),
|
|
196
|
+
}),
|
|
197
|
+
];
|
|
198
|
+
|
|
199
|
+
if (options.nullable) {
|
|
200
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
201
|
+
} else {
|
|
202
|
+
decorators.push(
|
|
203
|
+
NotEquals(null, {
|
|
204
|
+
each: options.each,
|
|
205
|
+
message: i18nValidationMessage('validation.NOT_EQUALS'),
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (options.swagger !== false) {
|
|
211
|
+
decorators.push(
|
|
212
|
+
ApiProperty({ type: String, ...options, isArray: options.each }),
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const minLength = options.minLength ?? 1;
|
|
217
|
+
|
|
218
|
+
decorators.push(
|
|
219
|
+
MinLength(minLength, {
|
|
220
|
+
each: options.each,
|
|
221
|
+
message: i18nValidationMessage('validation.MIN_LENGTH'),
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
if (options.maxLength) {
|
|
226
|
+
decorators.push(
|
|
227
|
+
MaxLength(options.maxLength, {
|
|
228
|
+
each: options.each,
|
|
229
|
+
message: i18nValidationMessage('validation.MAX_LENGTH'),
|
|
230
|
+
}),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (options.toLowerCase) {
|
|
235
|
+
decorators.push(ToLowerCase());
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (options.toUpperCase) {
|
|
239
|
+
decorators.push(ToUpperCase());
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return applyDecorators(...decorators);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function StringFieldOptional(
|
|
246
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
247
|
+
IStringFieldOptions = {},
|
|
248
|
+
): PropertyDecorator {
|
|
249
|
+
return applyDecorators(
|
|
250
|
+
IsEmptyable(),
|
|
251
|
+
StringField({ required: false, ...options }),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function PasswordField(
|
|
256
|
+
options: Omit<ApiPropertyOptions, 'type' | 'minLength'> &
|
|
257
|
+
IStringFieldOptions = {},
|
|
258
|
+
): PropertyDecorator {
|
|
259
|
+
const decorators = [
|
|
260
|
+
StringField({ ...options, minLength: 6 }) /*IsPassword()*/,
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
if (options.nullable) {
|
|
264
|
+
decorators.push(IsNullable());
|
|
265
|
+
} else {
|
|
266
|
+
decorators.push(NotEquals(null));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return applyDecorators(...decorators);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function PasswordFieldOptional(
|
|
273
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required' | 'minLength'> &
|
|
274
|
+
IStringFieldOptions = {},
|
|
275
|
+
): PropertyDecorator {
|
|
276
|
+
return applyDecorators(
|
|
277
|
+
IsEmptyable(),
|
|
278
|
+
PasswordField({ required: false, ...options }),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function BooleanField(
|
|
283
|
+
options: Omit<ApiPropertyOptions, 'type'> & IBooleanFieldOptions = {},
|
|
284
|
+
): PropertyDecorator {
|
|
285
|
+
const decorators = [
|
|
286
|
+
ToBoolean(),
|
|
287
|
+
IsBoolean({ message: 'validation.INVALID_BOOLEAN' }),
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
if (options.nullable) {
|
|
291
|
+
decorators.push(IsNullable());
|
|
292
|
+
} else {
|
|
293
|
+
decorators.push(NotEquals(null));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (options.swagger !== false) {
|
|
297
|
+
decorators.push(ApiProperty({ type: Boolean, ...options }));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return applyDecorators(...decorators);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function BooleanFieldOptional(
|
|
304
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
305
|
+
IBooleanFieldOptions = {},
|
|
306
|
+
): PropertyDecorator {
|
|
307
|
+
return applyDecorators(
|
|
308
|
+
IsEmptyable(),
|
|
309
|
+
BooleanField({ required: false, ...options }),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function TranslationsField(
|
|
314
|
+
options: RequireField<Omit<ApiPropertyOptions, 'isArray'>, 'type'> &
|
|
315
|
+
IFieldOptions,
|
|
316
|
+
): PropertyDecorator {
|
|
317
|
+
const decorators = [
|
|
318
|
+
ArrayMinSize(supportedLanguageCount),
|
|
319
|
+
ArrayMaxSize(supportedLanguageCount),
|
|
320
|
+
ValidateNested({
|
|
321
|
+
each: true,
|
|
322
|
+
}),
|
|
323
|
+
Type(() => options.type as FunctionConstructor),
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
if (options.nullable) {
|
|
327
|
+
decorators.push(IsNullable());
|
|
328
|
+
} else {
|
|
329
|
+
decorators.push(NotEquals(null));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (options.swagger !== false) {
|
|
333
|
+
decorators.push(ApiProperty({ isArray: true, ...options }));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return applyDecorators(...decorators);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function TranslationsFieldOptional(
|
|
340
|
+
options: RequireField<Omit<ApiPropertyOptions, 'isArray'>, 'type'> &
|
|
341
|
+
IFieldOptions,
|
|
342
|
+
): PropertyDecorator {
|
|
343
|
+
return applyDecorators(
|
|
344
|
+
IsEmptyable(),
|
|
345
|
+
TranslationsField({ required: false, ...options }),
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export function TmpKeyField(
|
|
350
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
351
|
+
): PropertyDecorator {
|
|
352
|
+
const decorators = [
|
|
353
|
+
StringField(options),
|
|
354
|
+
IsTemporaryKey({ each: options.each }),
|
|
355
|
+
];
|
|
356
|
+
|
|
357
|
+
if (options.nullable) {
|
|
358
|
+
decorators.push(IsNullable());
|
|
359
|
+
} else {
|
|
360
|
+
decorators.push(NotEquals(null));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (options.swagger !== false) {
|
|
364
|
+
decorators.push(
|
|
365
|
+
ApiProperty({ type: String, ...options, isArray: options.each }),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return applyDecorators(...decorators);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function TmpKeyFieldOptional(
|
|
373
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
374
|
+
IStringFieldOptions = {},
|
|
375
|
+
): PropertyDecorator {
|
|
376
|
+
return applyDecorators(
|
|
377
|
+
IsEmptyable(),
|
|
378
|
+
TmpKeyField({ required: false, ...options }),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function getEnumDescription(enumType: any): string {
|
|
383
|
+
const keys = Object.keys(enumType).filter(
|
|
384
|
+
(k) => typeof enumType[k as any] === 'number',
|
|
385
|
+
);
|
|
386
|
+
return keys.map((k) => `${enumType[k]}: ${k}`).join(', ');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
390
|
+
export function EnumField<TEnum extends object>(
|
|
391
|
+
getEnum: () => TEnum,
|
|
392
|
+
options: Omit<ApiPropertyOptions, 'type' | 'enum' | 'enumName' | 'isArray'> &
|
|
393
|
+
IEnumFieldOptions = {},
|
|
394
|
+
): PropertyDecorator {
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/ban-types
|
|
396
|
+
const enumValue = getEnum();
|
|
397
|
+
const decorators = [
|
|
398
|
+
IsEnum(enumValue, {
|
|
399
|
+
each: options.each,
|
|
400
|
+
message: i18nValidationMessage('validation.IS_ENUM'),
|
|
401
|
+
}),
|
|
402
|
+
];
|
|
403
|
+
|
|
404
|
+
if (options.nullable) {
|
|
405
|
+
decorators.push(IsNullable());
|
|
406
|
+
} else {
|
|
407
|
+
decorators.push(NotEquals(null));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (options.each) {
|
|
411
|
+
decorators.push(ToArray());
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (options.swagger !== false) {
|
|
415
|
+
decorators.push(
|
|
416
|
+
ApiEnumProperty(getEnum, {
|
|
417
|
+
...options,
|
|
418
|
+
isArray: options.each,
|
|
419
|
+
}),
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return applyDecorators(...decorators);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
427
|
+
export function ClassField<TClass extends object>(
|
|
428
|
+
getClass: () => TClass,
|
|
429
|
+
options: Omit<ApiPropertyOptions, 'type'> & IClassFieldOptions = {},
|
|
430
|
+
): PropertyDecorator {
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
432
|
+
const classValue = getClass() as any;
|
|
433
|
+
|
|
434
|
+
if (!classValue) {
|
|
435
|
+
throw new Error('ClassField: recursive class definition');
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const decorators = [
|
|
439
|
+
Type(() => classValue),
|
|
440
|
+
ValidateNested({ each: options.each }),
|
|
441
|
+
];
|
|
442
|
+
|
|
443
|
+
if (options.required !== false) {
|
|
444
|
+
decorators.push(IsDefined());
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (options.nullable) {
|
|
448
|
+
decorators.push(IsNullable());
|
|
449
|
+
} else {
|
|
450
|
+
decorators.push(NotEquals(null));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (options.swagger !== false) {
|
|
454
|
+
decorators.push(
|
|
455
|
+
ApiProperty({
|
|
456
|
+
type: () => classValue,
|
|
457
|
+
isArray: options.each,
|
|
458
|
+
...options,
|
|
459
|
+
}),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (options.each) {
|
|
464
|
+
decorators.push(ToArray());
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return applyDecorators(...decorators);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
471
|
+
export function EnumFieldOptional<TEnum extends object>(
|
|
472
|
+
getEnum: () => TEnum,
|
|
473
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required' | 'enum' | 'enumName'> &
|
|
474
|
+
IEnumFieldOptions = {},
|
|
475
|
+
): PropertyDecorator {
|
|
476
|
+
return applyDecorators(
|
|
477
|
+
IsEmptyable(),
|
|
478
|
+
EnumField(getEnum, { required: false, ...options }),
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
483
|
+
export function ClassFieldOptional<TClass extends object>(
|
|
484
|
+
getClass: () => TClass,
|
|
485
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
486
|
+
IClassFieldOptions = {},
|
|
487
|
+
): PropertyDecorator {
|
|
488
|
+
return applyDecorators(
|
|
489
|
+
IsEmptyable(),
|
|
490
|
+
ClassField(getClass, { required: false, ...options }),
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export function EmailField(
|
|
495
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
496
|
+
IStringFieldOptions &
|
|
497
|
+
IEmailFieldOptions = {},
|
|
498
|
+
): PropertyDecorator {
|
|
499
|
+
const decorators = [
|
|
500
|
+
IsEmail(options.emailOptions, {
|
|
501
|
+
message:
|
|
502
|
+
options.message ?? i18nValidationMessage('validation.INVALID_EMAIL'),
|
|
503
|
+
...options,
|
|
504
|
+
}),
|
|
505
|
+
StringField({ toLowerCase: true, ...options }),
|
|
506
|
+
];
|
|
507
|
+
|
|
508
|
+
if (options.nullable) {
|
|
509
|
+
decorators.push(IsNullable());
|
|
510
|
+
} else {
|
|
511
|
+
decorators.push(NotEquals(null));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (options.swagger !== false) {
|
|
515
|
+
decorators.push(ApiProperty({ type: String, ...options }));
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return applyDecorators(...decorators);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export function EmailFieldOptional(
|
|
522
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
523
|
+
IStringFieldOptions &
|
|
524
|
+
IEmailFieldOptions = {},
|
|
525
|
+
): PropertyDecorator {
|
|
526
|
+
return applyDecorators(
|
|
527
|
+
IsEmptyable(),
|
|
528
|
+
EmailField({ required: false, ...options }),
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function PhoneField(
|
|
533
|
+
options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions = {},
|
|
534
|
+
): PropertyDecorator {
|
|
535
|
+
const decorators = [IsPhoneNumber(), PhoneNumberSerializer()];
|
|
536
|
+
|
|
537
|
+
if (options.nullable) {
|
|
538
|
+
decorators.push(IsNullable());
|
|
539
|
+
} else {
|
|
540
|
+
decorators.push(NotEquals(null));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (options.swagger !== false) {
|
|
544
|
+
decorators.push(ApiProperty({ type: String, ...options }));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return applyDecorators(...decorators);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export function PhoneFieldOptional(
|
|
551
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> & IFieldOptions = {},
|
|
552
|
+
): PropertyDecorator {
|
|
553
|
+
return applyDecorators(
|
|
554
|
+
IsEmptyable(),
|
|
555
|
+
PhoneField({ required: false, ...options }),
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export function UUIDField(
|
|
560
|
+
options: Omit<ApiPropertyOptions, 'type' | 'format' | 'isArray'> &
|
|
561
|
+
IFieldOptions = {},
|
|
562
|
+
): PropertyDecorator {
|
|
563
|
+
const decorators = [
|
|
564
|
+
Type(() => String),
|
|
565
|
+
IsUUID('4', {
|
|
566
|
+
each: options.each,
|
|
567
|
+
message: i18nValidationMessage('validation.IS_UUID'),
|
|
568
|
+
}),
|
|
569
|
+
];
|
|
570
|
+
|
|
571
|
+
if (options.nullable) {
|
|
572
|
+
decorators.push(
|
|
573
|
+
IsNullable({ message: i18nValidationMessage('validation.IS_NULLABLE') }),
|
|
574
|
+
);
|
|
575
|
+
} else {
|
|
576
|
+
decorators.push(NotEquals(null));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (options.swagger !== false) {
|
|
580
|
+
decorators.push(ApiUUIDProperty(options));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (options.each) {
|
|
584
|
+
decorators.push(ToArray());
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
return applyDecorators(...decorators);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export function UUIDFieldOptional(
|
|
591
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required' | 'isArray'> &
|
|
592
|
+
IFieldOptions = {},
|
|
593
|
+
): PropertyDecorator {
|
|
594
|
+
return applyDecorators(
|
|
595
|
+
IsEmptyable(),
|
|
596
|
+
UUIDField({ required: false, ...options }),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export function URLField(
|
|
601
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
602
|
+
IURLFieldOptions &
|
|
603
|
+
IStringFieldOptions = {},
|
|
604
|
+
): PropertyDecorator {
|
|
605
|
+
const decorators = [StringField({ ...options })];
|
|
606
|
+
if (options.simpleUrl) {
|
|
607
|
+
decorators.push(
|
|
608
|
+
IsHttpUrl({
|
|
609
|
+
each: options.each,
|
|
610
|
+
message: i18nValidationMessage('validation.IS_URL'),
|
|
611
|
+
}),
|
|
612
|
+
);
|
|
613
|
+
} else {
|
|
614
|
+
decorators.push(
|
|
615
|
+
IsUrl(options.urlOptions, {
|
|
616
|
+
each: options.each,
|
|
617
|
+
message: i18nValidationMessage('validation.IS_URL'),
|
|
618
|
+
}),
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (options.nullable) {
|
|
623
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
624
|
+
} else {
|
|
625
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return applyDecorators(...decorators);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export function URLFieldOptional(
|
|
632
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
633
|
+
IURLFieldOptions &
|
|
634
|
+
IStringFieldOptions = {},
|
|
635
|
+
): PropertyDecorator {
|
|
636
|
+
return applyDecorators(
|
|
637
|
+
IsEmptyable(),
|
|
638
|
+
URLField({ required: false, ...options }),
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export function FQDNField(
|
|
643
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
644
|
+
IFQDNFieldOptions &
|
|
645
|
+
IStringFieldOptions = {},
|
|
646
|
+
): PropertyDecorator {
|
|
647
|
+
const decorators = [
|
|
648
|
+
IsFQDN(options, {
|
|
649
|
+
each: options.each,
|
|
650
|
+
message: i18nValidationMessage('validation.IS_FQDN'),
|
|
651
|
+
}),
|
|
652
|
+
StringField({ toLowerCase: true, ...options }),
|
|
653
|
+
];
|
|
654
|
+
|
|
655
|
+
if (options.nullable) {
|
|
656
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
657
|
+
} else {
|
|
658
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return applyDecorators(...decorators);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export function FQDNFieldOptional(
|
|
665
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
666
|
+
IFQDNFieldOptions &
|
|
667
|
+
IStringFieldOptions = {},
|
|
668
|
+
): PropertyDecorator {
|
|
669
|
+
return applyDecorators(
|
|
670
|
+
IsEmptyable(),
|
|
671
|
+
FQDNField({ required: false, ...options }),
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export function DateField(
|
|
676
|
+
options: Omit<ApiPropertyOptions, 'type'> & IDateFieldOptions = {},
|
|
677
|
+
): PropertyDecorator {
|
|
678
|
+
const decorators = [
|
|
679
|
+
Type(() => Date),
|
|
680
|
+
IsDate({ message: i18nValidationMessage('validation.IS_DATE') }),
|
|
681
|
+
];
|
|
682
|
+
|
|
683
|
+
if (options.nullable) {
|
|
684
|
+
decorators.push(IsNullable());
|
|
685
|
+
} else {
|
|
686
|
+
decorators.push(NotEquals(null));
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (options.minDate) {
|
|
690
|
+
decorators.push(
|
|
691
|
+
MinDate(options.minDate, {
|
|
692
|
+
each: options.each,
|
|
693
|
+
message: i18nValidationMessage('validation.MIN_DATE'),
|
|
694
|
+
}),
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (options.maxDate) {
|
|
699
|
+
decorators.push(
|
|
700
|
+
MaxDate(options.maxDate, {
|
|
701
|
+
each: options.each,
|
|
702
|
+
message: i18nValidationMessage('validation.MAX_DATE'),
|
|
703
|
+
}),
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
if (options.swagger !== false) {
|
|
708
|
+
decorators.push(ApiProperty({ type: Date, ...options }));
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return applyDecorators(...decorators);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export function DateFieldOptional(
|
|
715
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> &
|
|
716
|
+
IDateFieldOptions = {},
|
|
717
|
+
): PropertyDecorator {
|
|
718
|
+
return applyDecorators(
|
|
719
|
+
IsEmptyable(),
|
|
720
|
+
DateField({ ...options, required: false }),
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
export function IpFieldOptional(
|
|
725
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
726
|
+
IIPFieldOptions &
|
|
727
|
+
IStringFieldOptions = {},
|
|
728
|
+
): PropertyDecorator {
|
|
729
|
+
return applyDecorators(
|
|
730
|
+
IsEmptyable(),
|
|
731
|
+
IpField({ required: false, ...options }),
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export function IpField(
|
|
736
|
+
options: Omit<ApiPropertyOptions, 'type'> &
|
|
737
|
+
IStringFieldOptions &
|
|
738
|
+
IIPFieldOptions,
|
|
739
|
+
): PropertyDecorator {
|
|
740
|
+
const decorators = [
|
|
741
|
+
IsIP(options.version || 4, {
|
|
742
|
+
each: options.each,
|
|
743
|
+
message: i18nValidationMessage('validation.IS_IP'),
|
|
744
|
+
}),
|
|
745
|
+
StringField({ toLowerCase: true, ...options }),
|
|
746
|
+
];
|
|
747
|
+
|
|
748
|
+
if (options.nullable) {
|
|
749
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
750
|
+
} else {
|
|
751
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return applyDecorators(...decorators);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
export function ObjectField(
|
|
758
|
+
options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions = {},
|
|
759
|
+
): PropertyDecorator {
|
|
760
|
+
const decorators = [
|
|
761
|
+
Type(() => Object),
|
|
762
|
+
IsObject({
|
|
763
|
+
each: options.each,
|
|
764
|
+
message: i18nValidationMessage('validation.IS_OBJECT'),
|
|
765
|
+
}),
|
|
766
|
+
];
|
|
767
|
+
|
|
768
|
+
if (options.nullable) {
|
|
769
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
770
|
+
} else {
|
|
771
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
if (options.swagger !== false) {
|
|
775
|
+
decorators.push(
|
|
776
|
+
ApiProperty({
|
|
777
|
+
type: 'object',
|
|
778
|
+
isArray: options.each,
|
|
779
|
+
...options,
|
|
780
|
+
}),
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
return applyDecorators(...decorators);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
export function ObjectFieldOptional(
|
|
788
|
+
options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions = {},
|
|
789
|
+
): PropertyDecorator {
|
|
790
|
+
return applyDecorators(
|
|
791
|
+
IsEmptyable(),
|
|
792
|
+
ObjectField({ required: false, ...options }),
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export function TimeZoneField(
|
|
797
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
798
|
+
): PropertyDecorator {
|
|
799
|
+
const decorators = [
|
|
800
|
+
StringField({ ...options }),
|
|
801
|
+
IsTimeZone({
|
|
802
|
+
each: options.each,
|
|
803
|
+
message: i18nValidationMessage('validation.IS_TIME_ZONE'),
|
|
804
|
+
}),
|
|
805
|
+
];
|
|
806
|
+
|
|
807
|
+
if (options.nullable) {
|
|
808
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
809
|
+
} else {
|
|
810
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
return applyDecorators(...decorators);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export function TimeZoneFieldOptional(
|
|
817
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
818
|
+
): PropertyDecorator {
|
|
819
|
+
return applyDecorators(
|
|
820
|
+
IsEmptyable(),
|
|
821
|
+
TimeZoneField({ required: false, ...options }),
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export function LocaleField(
|
|
826
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
827
|
+
): PropertyDecorator {
|
|
828
|
+
const decorators = [
|
|
829
|
+
StringField({ ...options }),
|
|
830
|
+
IsLocale({
|
|
831
|
+
each: options.each,
|
|
832
|
+
message: i18nValidationMessage('validation.IS_LOCALE'),
|
|
833
|
+
}),
|
|
834
|
+
];
|
|
835
|
+
|
|
836
|
+
if (options.nullable) {
|
|
837
|
+
decorators.push(IsNullable({ each: options.each }));
|
|
838
|
+
} else {
|
|
839
|
+
decorators.push(NotEquals(null, { each: options.each }));
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
if (options.swagger !== false) {
|
|
843
|
+
decorators.push(ApiProperty({ type: String, ...options }));
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
return applyDecorators(...decorators);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
export function LocaleFieldOptional(
|
|
850
|
+
options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
|
|
851
|
+
): PropertyDecorator {
|
|
852
|
+
return applyDecorators(
|
|
853
|
+
IsEmptyable(),
|
|
854
|
+
LocaleField({ required: false, ...options }),
|
|
855
|
+
);
|
|
856
|
+
}
|