@nest-omni/core 1.0.57 → 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/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.d.ts +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,10 @@
|
|
|
1
|
+
import type { PipeTransform } from '@nestjs/common';
|
|
2
|
+
import { Param, ParseUUIDPipe } from '@nestjs/common';
|
|
3
|
+
import type { Type } from '@nestjs/common/interfaces';
|
|
4
|
+
|
|
5
|
+
export function UUIDParam(
|
|
6
|
+
property: string,
|
|
7
|
+
...pipes: Array<Type<PipeTransform> | PipeTransform>
|
|
8
|
+
): ParameterDecorator {
|
|
9
|
+
return Param(property, new ParseUUIDPipe({ version: '4' }), ...pipes);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './api-page-ok-response.decorator';
|
|
2
|
+
export * from './auth-user.decorator';
|
|
3
|
+
export * from './field.decorators';
|
|
4
|
+
export * from './http.decorators';
|
|
5
|
+
export * from './property.decorators';
|
|
6
|
+
export * from './public-route.decorator';
|
|
7
|
+
export * from './swagger.schema';
|
|
8
|
+
export * from './transform.decorators';
|
|
9
|
+
export * from './translate.decorator';
|
|
10
|
+
export * from './use-dto.decorator';
|
|
11
|
+
export * from './validator.decorators';
|
|
12
|
+
export * from './controller.decorator';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
+
|
|
4
|
+
import { getVariableName } from '../common/utils';
|
|
5
|
+
import { getEnumDescription } from '../decorators/field.decorators';
|
|
6
|
+
|
|
7
|
+
export function ApiBooleanProperty(
|
|
8
|
+
options: Omit<ApiPropertyOptions, 'type'> = {},
|
|
9
|
+
): PropertyDecorator {
|
|
10
|
+
return ApiProperty({ type: Boolean, ...options });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ApiBooleanPropertyOptional(
|
|
14
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> = {},
|
|
15
|
+
): PropertyDecorator {
|
|
16
|
+
return ApiBooleanProperty({ required: false, ...options });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ApiUUIDProperty(
|
|
20
|
+
options: Omit<ApiPropertyOptions, 'type' | 'format'> &
|
|
21
|
+
Partial<{ each: boolean }> = {},
|
|
22
|
+
): PropertyDecorator {
|
|
23
|
+
return ApiProperty({
|
|
24
|
+
type: options.each ? [String] : String,
|
|
25
|
+
format: 'uuid',
|
|
26
|
+
isArray: options.each,
|
|
27
|
+
...options,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ApiUUIDPropertyOptional(
|
|
32
|
+
options: Omit<ApiPropertyOptions, 'type' | 'format' | 'required'> &
|
|
33
|
+
Partial<{ each: boolean }> = {},
|
|
34
|
+
): PropertyDecorator {
|
|
35
|
+
return ApiUUIDProperty({ required: false, ...options });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function ApiEnumProperty<TEnum>(
|
|
39
|
+
getEnum: () => TEnum,
|
|
40
|
+
options: Omit<ApiPropertyOptions, 'type'> & { each?: boolean } = {},
|
|
41
|
+
): PropertyDecorator {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const enumValue = getEnum() as any;
|
|
44
|
+
options.description = getEnumDescription(enumValue);
|
|
45
|
+
return ApiProperty({
|
|
46
|
+
type: 'enum',
|
|
47
|
+
// throw error during the compilation of swagger
|
|
48
|
+
// isArray: options.each,
|
|
49
|
+
enum: enumValue,
|
|
50
|
+
enumName: getVariableName(getEnum),
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function ApiEnumPropertyOptional<TEnum>(
|
|
56
|
+
getEnum: () => TEnum,
|
|
57
|
+
options: Omit<ApiPropertyOptions, 'type' | 'required'> & {
|
|
58
|
+
each?: boolean;
|
|
59
|
+
} = {},
|
|
60
|
+
): PropertyDecorator {
|
|
61
|
+
return ApiEnumProperty(getEnum, { required: false, ...options });
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CustomDecorator } from '@nestjs/common';
|
|
2
|
+
import { SetMetadata } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
export const PUBLIC_ROUTE_KEY = 'public_route';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const PublicRoute = (isPublic = false): CustomDecorator =>
|
|
8
|
+
SetMetadata(PUBLIC_ROUTE_KEY, isPublic);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-unsafe-argument */
|
|
2
|
+
import type { Type } from '@nestjs/common';
|
|
3
|
+
import { applyDecorators, UseInterceptors } from '@nestjs/common';
|
|
4
|
+
import { PARAMTYPES_METADATA, ROUTE_ARGS_METADATA } from '@nestjs/common/constants';
|
|
5
|
+
import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
|
|
6
|
+
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
|
7
|
+
import { ApiBody, ApiConsumes, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
|
|
8
|
+
import type { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
9
|
+
import { reverseObjectKeys } from '@nestjs/swagger/dist/utils/reverse-object-keys.util';
|
|
10
|
+
import _ from 'lodash';
|
|
11
|
+
|
|
12
|
+
import type { IApiFile } from '../interfaces';
|
|
13
|
+
|
|
14
|
+
function explore(instance: Object, propertyKey: string | symbol) {
|
|
15
|
+
const types: Array<Type<unknown>> = Reflect.getMetadata(
|
|
16
|
+
PARAMTYPES_METADATA,
|
|
17
|
+
instance,
|
|
18
|
+
propertyKey,
|
|
19
|
+
);
|
|
20
|
+
const routeArgsMetadata =
|
|
21
|
+
Reflect.getMetadata(
|
|
22
|
+
ROUTE_ARGS_METADATA,
|
|
23
|
+
instance.constructor,
|
|
24
|
+
propertyKey,
|
|
25
|
+
) || {};
|
|
26
|
+
|
|
27
|
+
const parametersWithType = _.mapValues(
|
|
28
|
+
reverseObjectKeys(routeArgsMetadata),
|
|
29
|
+
(param) => ({
|
|
30
|
+
type: types[param.index],
|
|
31
|
+
name: param.data,
|
|
32
|
+
required: true,
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
for (const [key, value] of Object.entries(parametersWithType)) {
|
|
37
|
+
const keyPair = key.split(':');
|
|
38
|
+
|
|
39
|
+
if (Number(keyPair[0]) === RouteParamtypes.BODY) {
|
|
40
|
+
return value.type;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function RegisterModels(): MethodDecorator {
|
|
46
|
+
return (target, propertyKey, descriptor: PropertyDescriptor) => {
|
|
47
|
+
const body = explore(target, propertyKey);
|
|
48
|
+
|
|
49
|
+
return body && ApiExtraModels(body)(target, propertyKey, descriptor);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ApiFileDecorator(
|
|
54
|
+
files: IApiFile[] = [],
|
|
55
|
+
options: Partial<{ isRequired: boolean }> = {},
|
|
56
|
+
): MethodDecorator {
|
|
57
|
+
return (target, propertyKey, descriptor: PropertyDescriptor) => {
|
|
58
|
+
const { isRequired = false } = options;
|
|
59
|
+
const fileSchema: SchemaObject = {
|
|
60
|
+
type: 'string',
|
|
61
|
+
format: 'binary',
|
|
62
|
+
};
|
|
63
|
+
const properties: Record<string, SchemaObject | ReferenceObject> = {};
|
|
64
|
+
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
if (file.isArray) {
|
|
67
|
+
properties[file.name] = {
|
|
68
|
+
type: 'array',
|
|
69
|
+
items: fileSchema,
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
properties[file.name] = fileSchema;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let schema: SchemaObject = {
|
|
77
|
+
properties,
|
|
78
|
+
type: 'object',
|
|
79
|
+
};
|
|
80
|
+
const body = explore(target, propertyKey);
|
|
81
|
+
|
|
82
|
+
if (body) {
|
|
83
|
+
schema = {
|
|
84
|
+
allOf: [
|
|
85
|
+
{
|
|
86
|
+
$ref: getSchemaPath(body),
|
|
87
|
+
},
|
|
88
|
+
{ properties, type: 'object' },
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return ApiBody({
|
|
94
|
+
schema,
|
|
95
|
+
required: isRequired,
|
|
96
|
+
})(target, propertyKey, descriptor);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function ApiFile(
|
|
101
|
+
files: _.Many<IApiFile>,
|
|
102
|
+
options: Partial<{ isRequired: boolean }> = {},
|
|
103
|
+
): MethodDecorator {
|
|
104
|
+
const filesArray = _.castArray(files);
|
|
105
|
+
const apiFileInterceptors = filesArray.map((file) =>
|
|
106
|
+
file.isArray
|
|
107
|
+
? UseInterceptors(FilesInterceptor(file.name))
|
|
108
|
+
: UseInterceptors(FileInterceptor(file.name)),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return applyDecorators(
|
|
112
|
+
RegisterModels(),
|
|
113
|
+
ApiConsumes('multipart/form-data'),
|
|
114
|
+
ApiFileDecorator(filesArray, options),
|
|
115
|
+
...apiFileInterceptors,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { applyDecorators } from '@nestjs/common';
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
+
import { Column } from 'typeorm';
|
|
4
|
+
import { formatDateTime, strToTimeStamp } from '../helpers';
|
|
5
|
+
|
|
6
|
+
export function TimestampColumn(name: string, description?: string) {
|
|
7
|
+
return applyDecorators(
|
|
8
|
+
ApiProperty({
|
|
9
|
+
required: false,
|
|
10
|
+
type: 'string',
|
|
11
|
+
format: 'date-time',
|
|
12
|
+
example: '2018-10-01 12:18:48',
|
|
13
|
+
description,
|
|
14
|
+
}),
|
|
15
|
+
Column({
|
|
16
|
+
type: 'int',
|
|
17
|
+
name,
|
|
18
|
+
nullable: false,
|
|
19
|
+
unsigned: true,
|
|
20
|
+
default: 0,
|
|
21
|
+
comment: description,
|
|
22
|
+
transformer: {
|
|
23
|
+
to: (value) =>
|
|
24
|
+
value === 0 || /\d{10}/.test(value) ? value : strToTimeStamp(value),
|
|
25
|
+
from: (value) => formatDateTime(value),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Transform, TransformationType } from 'class-transformer';
|
|
2
|
+
import { parsePhoneNumber } from 'libphonenumber-js';
|
|
3
|
+
import { castArray, isArray, map, trim } from 'lodash';
|
|
4
|
+
|
|
5
|
+
import { GeneratorProvider } from '../providers';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @description trim spaces from start and end, replace multiple spaces with one.
|
|
9
|
+
* @example
|
|
10
|
+
* @ApiProperty()
|
|
11
|
+
* @IsString()
|
|
12
|
+
* @Trim()
|
|
13
|
+
* name: string;
|
|
14
|
+
* @returns PropertyDecorator
|
|
15
|
+
* @constructor
|
|
16
|
+
*/
|
|
17
|
+
export function Trim(): PropertyDecorator {
|
|
18
|
+
return Transform((params) => {
|
|
19
|
+
const value = params.value as string[] | string;
|
|
20
|
+
|
|
21
|
+
if (isArray(value)) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
return map(value, (v) => trim(v).replaceAll(/\s\s+/g, ' '));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
return trim(value).replaceAll(/\s\s+/g, ' ');
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ToBoolean(): PropertyDecorator {
|
|
32
|
+
return Transform(
|
|
33
|
+
(params) => {
|
|
34
|
+
switch (params.value) {
|
|
35
|
+
case 'true': {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
case 'false': {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
default: {
|
|
44
|
+
return params.value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{ toClassOnly: true },
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description convert string or number to integer
|
|
54
|
+
* @example
|
|
55
|
+
* @IsNumber()
|
|
56
|
+
* @ToInt()
|
|
57
|
+
* name: number;
|
|
58
|
+
* @returns PropertyDecorator
|
|
59
|
+
* @constructor
|
|
60
|
+
*/
|
|
61
|
+
export function ToInt(): PropertyDecorator {
|
|
62
|
+
return Transform(
|
|
63
|
+
(params) => {
|
|
64
|
+
const value = params.value as string;
|
|
65
|
+
|
|
66
|
+
return Number.parseInt(value, 10);
|
|
67
|
+
},
|
|
68
|
+
{ toClassOnly: true },
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @description transforms to array, specially for query params
|
|
74
|
+
* @example
|
|
75
|
+
* @IsNumber()
|
|
76
|
+
* @ToArray()
|
|
77
|
+
* name: number;
|
|
78
|
+
* @constructor
|
|
79
|
+
*/
|
|
80
|
+
export function ToArray(): PropertyDecorator {
|
|
81
|
+
return Transform(
|
|
82
|
+
(params): unknown[] => {
|
|
83
|
+
const value = params.value;
|
|
84
|
+
|
|
85
|
+
if (!value) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return castArray(value);
|
|
90
|
+
},
|
|
91
|
+
{ toClassOnly: true },
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function ToLowerCase(): PropertyDecorator {
|
|
96
|
+
return Transform(
|
|
97
|
+
(params) => {
|
|
98
|
+
const value = params.value;
|
|
99
|
+
|
|
100
|
+
if (!value) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!Array.isArray(value)) {
|
|
105
|
+
return value.toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return value.map((v) => v.toLowerCase());
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
toClassOnly: true,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function ToUpperCase(): PropertyDecorator {
|
|
117
|
+
return Transform(
|
|
118
|
+
(params) => {
|
|
119
|
+
const value = params.value;
|
|
120
|
+
|
|
121
|
+
if (!value) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!Array.isArray(value)) {
|
|
126
|
+
return value.toUpperCase();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return value.map((v) => v.toUpperCase());
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
toClassOnly: true,
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function S3UrlParser(): PropertyDecorator {
|
|
138
|
+
return Transform((params) => {
|
|
139
|
+
const key = params.value as string;
|
|
140
|
+
|
|
141
|
+
switch (params.type) {
|
|
142
|
+
case TransformationType.CLASS_TO_PLAIN: {
|
|
143
|
+
return GeneratorProvider.getS3PublicUrl(key);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
case TransformationType.PLAIN_TO_CLASS: {
|
|
147
|
+
return GeneratorProvider.getS3Key(key);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
default: {
|
|
151
|
+
return key;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function PhoneNumberSerializer(): PropertyDecorator {
|
|
158
|
+
return Transform((params) => parsePhoneNumber(params.value as string).number);
|
|
159
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ITranslationDecoratorInterface } from '../interfaces';
|
|
2
|
+
|
|
3
|
+
export const STATIC_TRANSLATION_DECORATOR_KEY = 'custom:static-translate';
|
|
4
|
+
export const DYNAMIC_TRANSLATION_DECORATOR_KEY = 'custom:dynamic-translate';
|
|
5
|
+
|
|
6
|
+
// FIXME: This is a temporary solution to get the translation decorator working.
|
|
7
|
+
export function StaticTranslate(
|
|
8
|
+
data: ITranslationDecoratorInterface = {},
|
|
9
|
+
): PropertyDecorator {
|
|
10
|
+
return (target, key) => {
|
|
11
|
+
Reflect.defineMetadata(STATIC_TRANSLATION_DECORATOR_KEY, data, target, key);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function DynamicTranslate(): PropertyDecorator {
|
|
16
|
+
return (target, key) => {
|
|
17
|
+
Reflect.defineMetadata(DYNAMIC_TRANSLATION_DECORATOR_KEY, {}, target, key);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AbstractEntity } from '../common/abstract.entity';
|
|
2
|
+
import type { AbstractDto } from '../common/dto/abstract.dto';
|
|
3
|
+
import type { Constructor } from '../common/types';
|
|
4
|
+
|
|
5
|
+
export function UseDto(
|
|
6
|
+
dtoClass: Constructor<AbstractDto, [AbstractEntity, unknown]>,
|
|
7
|
+
): ClassDecorator {
|
|
8
|
+
return (ctor) => {
|
|
9
|
+
ctor.prototype.dtoClass = dtoClass;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import * as lodash from 'lodash';
|
|
3
|
+
|
|
4
|
+
export interface IUser {
|
|
5
|
+
uid: number;
|
|
6
|
+
username: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const User = createParamDecorator(
|
|
10
|
+
(data: string, ctx: ExecutionContext): IUser => {
|
|
11
|
+
return getUserData(ctx.switchToHttp().getRequest(), data);
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export function getUserData(req, data?: string): IUser | null {
|
|
16
|
+
const headers = req.headers;
|
|
17
|
+
if (
|
|
18
|
+
lodash.isEmpty(headers['x-user-id']) ||
|
|
19
|
+
lodash.isEmpty(headers['x-username'])
|
|
20
|
+
) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const user = {
|
|
25
|
+
uid: headers['x-user-id'],
|
|
26
|
+
username: headers['x-username'],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return data ? user[data] : user;
|
|
30
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createParamDecorator } from '@nestjs/common';
|
|
2
|
+
import { isEmpty } from 'lodash';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { ContextProvider } from '../providers';
|
|
5
|
+
|
|
6
|
+
export interface IUser {
|
|
7
|
+
uid: string;
|
|
8
|
+
username: string;
|
|
9
|
+
tenantId: string;
|
|
10
|
+
appId: string;
|
|
11
|
+
admin: boolean;
|
|
12
|
+
role: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const User = createParamDecorator(
|
|
16
|
+
(key?: keyof IUser): IUser | IUser[keyof IUser] => {
|
|
17
|
+
const authUser = ContextProvider.getAuthUser();
|
|
18
|
+
return key ? authUser[key] : authUser;
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export function getOmniAuthData<T extends keyof IUser>(
|
|
23
|
+
request: { headers: Record<string, string> },
|
|
24
|
+
key?: T,
|
|
25
|
+
): IUser[T] | IUser {
|
|
26
|
+
const headers = request.headers;
|
|
27
|
+
let user: IUser;
|
|
28
|
+
const configService = new ConfigService(request);
|
|
29
|
+
|
|
30
|
+
// 未通过网关透传用户信息且处于local开发环境,则从配置获取用户信息
|
|
31
|
+
if (isEmpty(headers['x-user-id']) && isEmpty(headers['x-app-id'])) {
|
|
32
|
+
if (process.env.NODE_ENV === 'dev') {
|
|
33
|
+
user = {
|
|
34
|
+
uid: configService.get('MOCK_UID'),
|
|
35
|
+
username: configService.get('MOCK_USERNAME'),
|
|
36
|
+
appId: configService.get('MOCK_APP_ID'),
|
|
37
|
+
tenantId: configService.get('MOCK_TENANT_ID'),
|
|
38
|
+
admin: configService.get('MOCK_ADMIN', false),
|
|
39
|
+
role: configService.get('MOCK_ROLE', ''),
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
console.debug(
|
|
43
|
+
'User information is not transparently transmitted through the gateway: ' +
|
|
44
|
+
JSON.stringify(headers),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
user = {
|
|
49
|
+
uid: headers['x-user-id'] || '',
|
|
50
|
+
username: headers['x-username'] || '',
|
|
51
|
+
appId: headers['x-app-id'] || '',
|
|
52
|
+
tenantId: headers['x-tenant-id'] || '',
|
|
53
|
+
admin: headers['x-admin'] === '1',
|
|
54
|
+
role: headers['x-role'] || '',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return key ? user[key] : user;
|
|
59
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { applyDecorators } from '@nestjs/common';
|
|
2
|
+
import { CrudAuth } from '@dataui/crud';
|
|
3
|
+
import { getOmniAuthData } from './user.decorator';
|
|
4
|
+
|
|
5
|
+
export function UserFilter(field: string) {
|
|
6
|
+
const obj = {};
|
|
7
|
+
return applyDecorators(
|
|
8
|
+
CrudAuth({
|
|
9
|
+
filter: (req) => {
|
|
10
|
+
obj[field] = getOmniAuthData(req, 'uid');
|
|
11
|
+
return obj;
|
|
12
|
+
},
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
}
|
|
79
|
+
|
|
80
|
+
export function IsHttpUrl(validationOptions?: ValidationOptions) {
|
|
81
|
+
return function (object, propertyName: string) {
|
|
82
|
+
registerDecorator({
|
|
83
|
+
name: 'isHttpUrl',
|
|
84
|
+
target: object.constructor,
|
|
85
|
+
propertyName: propertyName,
|
|
86
|
+
options: validationOptions,
|
|
87
|
+
validator: {
|
|
88
|
+
validate(value: any) {
|
|
89
|
+
const httpUrlPattern = /^(https?:\/\/)/i;
|
|
90
|
+
return typeof value === 'string' && httpUrlPattern.test(value);
|
|
91
|
+
},
|
|
92
|
+
defaultMessage(): string {
|
|
93
|
+
return 'URL must start with http:// or https://';
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|