@nest-omni/core 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -4
- package/src/boilerplate.polyfill.js +78 -0
- package/src/boilerplate.polyfill.ts +202 -0
- package/{dist → src}/common/abstract-client.service.d.ts +4 -0
- package/src/common/abstract-client.service.js +39 -0
- package/src/common/abstract-client.service.ts +56 -0
- package/{dist → src}/common/abstract.entity.d.ts +7 -0
- package/src/common/abstract.entity.js +152 -0
- package/src/common/abstract.entity.ts +73 -0
- package/src/common/dto/abstract.dto.js +96 -0
- package/src/common/dto/abstract.dto.ts +64 -0
- package/src/common/dto/bulk-id.dto.js +63 -0
- package/src/common/dto/bulk-id.dto.ts +13 -0
- package/src/common/dto/create-translation.dto.js +63 -0
- package/src/common/dto/create-translation.dto.ts +10 -0
- package/src/common/dto/page-meta.dto.js +88 -0
- package/src/common/dto/page-meta.dto.ts +37 -0
- package/src/common/dto/page-options.dto.js +87 -0
- package/src/common/dto/page-options.dto.ts +35 -0
- package/src/common/dto/page.dto.js +94 -0
- package/src/common/dto/page.dto.ts +36 -0
- package/{dist → src}/common/utils.d.ts +11 -0
- package/{dist → src}/common/utils.js +15 -2
- package/src/common/utils.ts +45 -0
- package/{dist → src}/constants/index.js +0 -1
- package/src/constants/index.ts +4 -0
- package/{dist → src}/constants/language-code.js +1 -1
- package/src/constants/language-code.ts +7 -0
- package/{dist → src}/constants/order.js +0 -1
- package/src/constants/order.ts +4 -0
- package/{dist → src}/constants/role-type.js +0 -1
- package/src/constants/role-type.ts +4 -0
- package/{dist → src}/constants/token-type.js +0 -1
- package/src/constants/token-type.ts +4 -0
- package/{dist → src}/decorators/api-page-ok-response.decorator.js +0 -1
- package/src/decorators/api-page-ok-response.decorator.ts +31 -0
- package/{dist → src}/decorators/auth-user.decorator.js +1 -2
- package/src/decorators/auth-user.decorator.ts +16 -0
- package/src/decorators/controller.decorator.js +34 -0
- package/src/decorators/controller.decorator.ts +8 -0
- package/{dist → src}/decorators/field.decorators.js +42 -44
- package/src/decorators/field.decorators.ts +773 -0
- package/{dist → src}/decorators/http.decorators.js +0 -1
- package/src/decorators/http.decorators.ts +10 -0
- package/{dist → src}/decorators/index.js +0 -1
- package/src/decorators/index.ts +12 -0
- package/{dist → src}/decorators/omni-auth.decorator.js +26 -2
- package/src/decorators/omni-auth.decorator.ts +46 -0
- package/{dist → src}/decorators/operation.decorator.js +0 -1
- package/src/decorators/operation.decorator.ts +4 -0
- package/{dist → src}/decorators/property.decorators.js +10 -17
- package/src/decorators/property.decorators.ts +62 -0
- package/{dist → src}/decorators/public-route.decorator.js +1 -1
- package/src/decorators/public-route.decorator.ts +8 -0
- package/{dist → src}/decorators/swagger.schema.js +4 -2
- package/src/decorators/swagger.schema.ts +117 -0
- package/{dist → src}/decorators/timestamp-column.decorator.js +1 -2
- package/src/decorators/timestamp-column.decorator.ts +29 -0
- package/src/decorators/transform.decorators.d.ts +35 -0
- package/{dist → src}/decorators/transform.decorators.js +27 -1
- package/src/decorators/transform.decorators.ts +147 -0
- package/{dist → src}/decorators/translate.decorator.js +1 -1
- package/src/decorators/translate.decorator.ts +19 -0
- package/{dist → src}/decorators/use-dto.decorator.js +0 -1
- package/src/decorators/use-dto.decorator.ts +11 -0
- package/src/decorators/user-check.decorator.js +44 -0
- package/src/decorators/user-check.decorator.ts +30 -0
- package/{dist → src}/decorators/user.decorator.js +25 -2
- package/src/decorators/user.decorator.ts +48 -0
- package/{dist → src}/decorators/user_auth.decorator.js +0 -1
- package/src/decorators/user_auth.decorator.ts +15 -0
- package/{dist → src}/decorators/validator.decorators.js +1 -5
- package/src/decorators/validator.decorators.ts +78 -0
- package/{dist → src}/exceptions/file-not-image.exception.js +0 -1
- package/src/exceptions/file-not-image.exception.ts +7 -0
- package/{dist → src}/exceptions/index.js +0 -1
- package/src/exceptions/index.ts +2 -0
- package/{dist → src}/exceptions/page-type.exception.js +0 -1
- package/src/exceptions/page-type.exception.ts +7 -0
- package/{dist → src}/exceptions/user-not-found.exception.js +0 -1
- package/src/exceptions/user-not-found.exception.ts +7 -0
- package/src/filters/bad-request.filter.js +104 -0
- package/src/filters/bad-request.filter.ts +67 -0
- package/{dist → src}/filters/constraint-errors.js +1 -1
- package/src/filters/constraint-errors.ts +5 -0
- package/{dist → src}/filters/index.js +0 -1
- package/src/filters/index.ts +3 -0
- package/src/filters/query-failed.filter.js +81 -0
- package/src/filters/query-failed.filter.ts +32 -0
- package/src/health-checker/health-checker.controller.js +104 -0
- package/src/health-checker/health-checker.controller.ts +51 -0
- package/src/health-checker/health-checker.module.js +69 -0
- package/src/health-checker/health-checker.module.ts +13 -0
- package/src/health-checker/health-indicators/service.indicator.js +102 -0
- package/src/health-checker/health-indicators/service.indicator.ts +44 -0
- package/src/helpers/common.helper.d.ts +16 -0
- package/{dist → src}/helpers/common.helper.js +13 -1
- package/src/helpers/common.helper.ts +49 -0
- package/{dist → src}/helpers/date.helper.d.ts +3 -3
- package/{dist → src}/helpers/date.helper.js +25 -3
- package/src/helpers/date.helper.ts +64 -0
- package/src/helpers/excel.helper.d.ts +27 -0
- package/src/helpers/excel.helper.js +338 -0
- package/{dist → src}/helpers/index.js +0 -1
- package/src/helpers/index.ts +3 -0
- package/src/i18n/en_US/validation.json +38 -0
- package/src/i18n/zh_CN/validation.json +38 -0
- package/{dist → src}/index.js +1 -1
- package/src/index.ts +12 -0
- package/src/interceptors/auth-user.interceptor.js +68 -0
- package/src/interceptors/auth-user.interceptor.ts +20 -0
- package/{dist → src}/interceptors/index.js +0 -1
- package/src/interceptors/index.ts +2 -0
- package/src/interceptors/language-interceptor.service.js +74 -0
- package/src/interceptors/language-interceptor.service.ts +31 -0
- package/src/interceptors/translation-interceptor.service.js +83 -0
- package/src/interceptors/translation-interceptor.service.ts +43 -0
- package/{dist → src}/interfaces/IApiFile.js +0 -1
- package/src/interfaces/IApiFile.ts +4 -0
- package/{dist → src}/interfaces/IFile.js +0 -1
- package/src/interfaces/IFile.ts +8 -0
- package/src/interfaces/ITranslationDecoratorInterface.js +2 -0
- package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
- package/{dist → src}/interfaces/index.js +0 -1
- package/src/interfaces/index.ts +3 -0
- package/{dist → src}/interfaces/response.js +0 -1
- package/src/interfaces/response.ts +37 -0
- package/{dist → src}/middlewares/index.js +0 -1
- package/src/middlewares/index.ts +3 -0
- package/{dist → src}/middlewares/omni-auth.middleware.js +0 -1
- package/src/middlewares/omni-auth.middleware.ts +10 -0
- package/{dist → src}/middlewares/powerby.middleware.js +0 -1
- package/src/middlewares/powerby.middleware.ts +6 -0
- package/{dist → src}/middlewares/request-id.middleware.js +0 -1
- package/src/middlewares/request-id.middleware.ts +28 -0
- package/{dist → src}/providers/context.provider.js +9 -7
- package/src/providers/context.provider.ts +98 -0
- package/{dist → src}/providers/generator.provider.d.ts +4 -0
- package/{dist → src}/providers/generator.provider.js +4 -1
- package/src/providers/generator.provider.ts +66 -0
- package/{dist → src}/providers/index.js +0 -1
- package/src/providers/index.ts +2 -0
- package/src/setup/bootstrap.setup.js +138 -0
- package/src/setup/bootstrap.setup.ts +139 -0
- package/{dist → src}/setup/index.js +0 -1
- package/src/setup/index.ts +1 -0
- package/src/setup/microservices.setup.js +55 -0
- package/{dist → src}/setup-swagger.js +0 -1
- package/src/setup-swagger.ts +67 -0
- package/{dist → src}/shared/index.js +0 -1
- package/src/shared/index.ts +2 -0
- package/src/shared/serviceRegistryModule.js +176 -0
- package/src/shared/serviceRegistryModule.ts +110 -0
- package/{dist → src}/shared/services/api-config.service.d.ts +3 -0
- package/src/shared/services/api-config.service.js +335 -0
- package/src/shared/services/api-config.service.ts +319 -0
- package/src/shared/services/aws-s3.service.js +96 -0
- package/src/shared/services/aws-s3.service.ts +39 -0
- package/src/shared/services/generator.service.js +67 -0
- package/src/shared/services/generator.service.ts +13 -0
- package/{dist → src}/shared/services/index.js +0 -1
- package/src/shared/services/index.ts +5 -0
- package/src/shared/services/translation.service.js +109 -0
- package/src/shared/services/translation.service.ts +59 -0
- package/src/shared/services/validator.service.js +64 -0
- package/src/shared/services/validator.service.ts +10 -0
- package/{dist → src}/snake-naming.strategy.js +3 -4
- package/src/snake-naming.strategy.ts +64 -0
- package/{dist → src}/types.js +0 -1
- package/src/types.ts +44 -0
- package/{dist → src}/validators/file-mimetype.validator.js +0 -3
- package/src/validators/file-mimetype.validator.ts +34 -0
- package/{dist → src}/validators/index.js +0 -1
- package/src/validators/index.ts +3 -0
- package/src/validators/is-exists.validator.js +99 -0
- package/src/validators/is-exists.validator.ts +60 -0
- package/src/validators/is-unique.validator.js +131 -0
- package/src/validators/is-unique.validator.ts +93 -0
- package/{dist → src}/validators/phone-country-code.validator.js +0 -1
- package/src/validators/phone-country-code.validator.ts +36 -0
- package/{dist → src}/validators/same-as.validator.js +1 -2
- package/src/validators/same-as.validator.ts +27 -0
- package/{dist → src}/validators/skip-empty.validator.d.ts +5 -0
- package/{dist → src}/validators/skip-empty.validator.js +5 -1
- package/src/validators/skip-empty.validator.ts +25 -0
- package/tsconfig.json +26 -0
- package/tsconfig.lib.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/boilerplate.polyfill.js +0 -66
- package/dist/boilerplate.polyfill.js.map +0 -1
- package/dist/common/abstract-client.service.js +0 -26
- package/dist/common/abstract-client.service.js.map +0 -1
- package/dist/common/abstract.entity.js +0 -71
- package/dist/common/abstract.entity.js.map +0 -1
- package/dist/common/dto/abstract.dto.js +0 -63
- package/dist/common/dto/abstract.dto.js.map +0 -1
- package/dist/common/dto/bulk-id.dto.js +0 -29
- package/dist/common/dto/bulk-id.dto.js.map +0 -1
- package/dist/common/dto/create-translation.dto.js +0 -28
- package/dist/common/dto/create-translation.dto.js.map +0 -1
- package/dist/common/dto/page-meta.dto.js +0 -55
- package/dist/common/dto/page-meta.dto.js.map +0 -1
- package/dist/common/dto/page-options.dto.js +0 -52
- package/dist/common/dto/page-options.dto.js.map +0 -1
- package/dist/common/dto/page.dto.js +0 -61
- package/dist/common/dto/page.dto.js.map +0 -1
- package/dist/common/utils.js.map +0 -1
- package/dist/constants/index.js.map +0 -1
- package/dist/constants/language-code.js.map +0 -1
- package/dist/constants/order.js.map +0 -1
- package/dist/constants/role-type.js.map +0 -1
- package/dist/constants/token-type.js.map +0 -1
- package/dist/decorators/api-page-ok-response.decorator.js.map +0 -1
- package/dist/decorators/auth-user.decorator.js.map +0 -1
- package/dist/decorators/controller.decorator.js +0 -12
- package/dist/decorators/controller.decorator.js.map +0 -1
- package/dist/decorators/field.decorators.js.map +0 -1
- package/dist/decorators/http.decorators.js.map +0 -1
- package/dist/decorators/index.js.map +0 -1
- package/dist/decorators/omni-auth.decorator.js.map +0 -1
- package/dist/decorators/operation.decorator.js.map +0 -1
- package/dist/decorators/property.decorators.js.map +0 -1
- package/dist/decorators/public-route.decorator.js.map +0 -1
- package/dist/decorators/swagger.schema.js.map +0 -1
- package/dist/decorators/timestamp-column.decorator.js.map +0 -1
- package/dist/decorators/transform.decorators.d.ts +0 -8
- package/dist/decorators/transform.decorators.js.map +0 -1
- package/dist/decorators/translate.decorator.js.map +0 -1
- package/dist/decorators/use-dto.decorator.js.map +0 -1
- package/dist/decorators/user-check.decorator.js +0 -22
- package/dist/decorators/user-check.decorator.js.map +0 -1
- package/dist/decorators/user.decorator.js.map +0 -1
- package/dist/decorators/user_auth.decorator.js.map +0 -1
- package/dist/decorators/validator.decorators.js.map +0 -1
- package/dist/exceptions/file-not-image.exception.js.map +0 -1
- package/dist/exceptions/index.js.map +0 -1
- package/dist/exceptions/page-type.exception.js.map +0 -1
- package/dist/exceptions/user-not-found.exception.js.map +0 -1
- package/dist/filters/bad-request.filter.js +0 -65
- package/dist/filters/bad-request.filter.js.map +0 -1
- package/dist/filters/constraint-errors.js.map +0 -1
- package/dist/filters/index.js.map +0 -1
- package/dist/filters/query-failed.filter.js +0 -43
- package/dist/filters/query-failed.filter.js.map +0 -1
- package/dist/health-checker/health-checker.controller.js +0 -68
- package/dist/health-checker/health-checker.controller.js.map +0 -1
- package/dist/health-checker/health-checker.module.js +0 -26
- package/dist/health-checker/health-checker.module.js.map +0 -1
- package/dist/health-checker/health-indicators/service.indicator.js +0 -57
- package/dist/health-checker/health-indicators/service.indicator.js.map +0 -1
- package/dist/helpers/common.helper.d.ts +0 -3
- package/dist/helpers/common.helper.js.map +0 -1
- package/dist/helpers/date.helper.js.map +0 -1
- package/dist/helpers/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interceptors/auth-user.interceptor.js +0 -25
- package/dist/interceptors/auth-user.interceptor.js.map +0 -1
- package/dist/interceptors/index.js.map +0 -1
- package/dist/interceptors/language-interceptor.service.js +0 -31
- package/dist/interceptors/language-interceptor.service.js.map +0 -1
- package/dist/interceptors/translation-interceptor.service.js +0 -35
- package/dist/interceptors/translation-interceptor.service.js.map +0 -1
- package/dist/interfaces/IApiFile.js.map +0 -1
- package/dist/interfaces/IFile.js.map +0 -1
- package/dist/interfaces/ITranslationDecoratorInterface.js +0 -3
- package/dist/interfaces/ITranslationDecoratorInterface.js.map +0 -1
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/response.js.map +0 -1
- package/dist/middlewares/index.js.map +0 -1
- package/dist/middlewares/omni-auth.middleware.js.map +0 -1
- package/dist/middlewares/powerby.middleware.js.map +0 -1
- package/dist/middlewares/request-id.middleware.js.map +0 -1
- package/dist/providers/context.provider.js.map +0 -1
- package/dist/providers/generator.provider.js.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/setup/bootstrap.setup.js +0 -102
- package/dist/setup/bootstrap.setup.js.map +0 -1
- package/dist/setup/index.js.map +0 -1
- package/dist/setup-swagger.js.map +0 -1
- package/dist/shared/index.js.map +0 -1
- package/dist/shared/serviceRegistryModule.js +0 -102
- package/dist/shared/serviceRegistryModule.js.map +0 -1
- package/dist/shared/services/api-config.service.js +0 -286
- package/dist/shared/services/api-config.service.js.map +0 -1
- package/dist/shared/services/aws-s3.service.js +0 -49
- package/dist/shared/services/aws-s3.service.js.map +0 -1
- package/dist/shared/services/generator.service.js +0 -24
- package/dist/shared/services/generator.service.js.map +0 -1
- package/dist/shared/services/index.js.map +0 -1
- package/dist/shared/services/translation.service.js +0 -61
- package/dist/shared/services/translation.service.js.map +0 -1
- package/dist/shared/services/validator.service.js +0 -21
- package/dist/shared/services/validator.service.js.map +0 -1
- package/dist/snake-naming.strategy.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validators/file-mimetype.validator.js.map +0 -1
- package/dist/validators/index.js.map +0 -1
- package/dist/validators/is-exists.validator.js +0 -52
- package/dist/validators/is-exists.validator.js.map +0 -1
- package/dist/validators/is-unique.validator.js +0 -83
- package/dist/validators/is-unique.validator.js.map +0 -1
- package/dist/validators/phone-country-code.validator.js.map +0 -1
- package/dist/validators/same-as.validator.js.map +0 -1
- package/dist/validators/skip-empty.validator.js.map +0 -1
- /package/{README → README.md} +0 -0
- /package/{dist → src}/boilerplate.polyfill.d.ts +0 -0
- /package/{dist → src}/common/dto/abstract.dto.d.ts +0 -0
- /package/{dist → src}/common/dto/bulk-id.dto.d.ts +0 -0
- /package/{dist → src}/common/dto/create-translation.dto.d.ts +0 -0
- /package/{dist → src}/common/dto/page-meta.dto.d.ts +0 -0
- /package/{dist → src}/common/dto/page-options.dto.d.ts +0 -0
- /package/{dist → src}/common/dto/page.dto.d.ts +0 -0
- /package/{dist → src}/constants/index.d.ts +0 -0
- /package/{dist → src}/constants/language-code.d.ts +0 -0
- /package/{dist → src}/constants/order.d.ts +0 -0
- /package/{dist → src}/constants/role-type.d.ts +0 -0
- /package/{dist → src}/constants/token-type.d.ts +0 -0
- /package/{dist → src}/decorators/api-page-ok-response.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/auth-user.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/controller.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/field.decorators.d.ts +0 -0
- /package/{dist → src}/decorators/http.decorators.d.ts +0 -0
- /package/{dist → src}/decorators/index.d.ts +0 -0
- /package/{dist → src}/decorators/omni-auth.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/operation.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/property.decorators.d.ts +0 -0
- /package/{dist → src}/decorators/public-route.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/swagger.schema.d.ts +0 -0
- /package/{dist → src}/decorators/timestamp-column.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/translate.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/use-dto.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/user-check.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/user.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/user_auth.decorator.d.ts +0 -0
- /package/{dist → src}/decorators/validator.decorators.d.ts +0 -0
- /package/{dist → src}/exceptions/file-not-image.exception.d.ts +0 -0
- /package/{dist → src}/exceptions/index.d.ts +0 -0
- /package/{dist → src}/exceptions/page-type.exception.d.ts +0 -0
- /package/{dist → src}/exceptions/user-not-found.exception.d.ts +0 -0
- /package/{dist → src}/filters/bad-request.filter.d.ts +0 -0
- /package/{dist → src}/filters/constraint-errors.d.ts +0 -0
- /package/{dist → src}/filters/index.d.ts +0 -0
- /package/{dist → src}/filters/query-failed.filter.d.ts +0 -0
- /package/{dist → src}/health-checker/health-checker.controller.d.ts +0 -0
- /package/{dist → src}/health-checker/health-checker.module.d.ts +0 -0
- /package/{dist → src}/health-checker/health-indicators/service.indicator.d.ts +0 -0
- /package/{dist → src}/helpers/index.d.ts +0 -0
- /package/{dist → src}/index.d.ts +0 -0
- /package/{dist → src}/interceptors/auth-user.interceptor.d.ts +0 -0
- /package/{dist → src}/interceptors/index.d.ts +0 -0
- /package/{dist → src}/interceptors/language-interceptor.service.d.ts +0 -0
- /package/{dist → src}/interceptors/translation-interceptor.service.d.ts +0 -0
- /package/{dist → src}/interfaces/IApiFile.d.ts +0 -0
- /package/{dist → src}/interfaces/IFile.d.ts +0 -0
- /package/{dist → src}/interfaces/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{dist → src}/interfaces/index.d.ts +0 -0
- /package/{dist → src}/interfaces/response.d.ts +0 -0
- /package/{dist → src}/middlewares/index.d.ts +0 -0
- /package/{dist → src}/middlewares/omni-auth.middleware.d.ts +0 -0
- /package/{dist → src}/middlewares/powerby.middleware.d.ts +0 -0
- /package/{dist → src}/middlewares/request-id.middleware.d.ts +0 -0
- /package/{dist → src}/providers/context.provider.d.ts +0 -0
- /package/{dist → src}/providers/index.d.ts +0 -0
- /package/{dist → src}/setup/bootstrap.setup.d.ts +0 -0
- /package/{dist → src}/setup/index.d.ts +0 -0
- /package/{dist → src}/setup-swagger.d.ts +0 -0
- /package/{dist → src}/shared/index.d.ts +0 -0
- /package/{dist → src}/shared/serviceRegistryModule.d.ts +0 -0
- /package/{dist → src}/shared/services/aws-s3.service.d.ts +0 -0
- /package/{dist → src}/shared/services/generator.service.d.ts +0 -0
- /package/{dist → src}/shared/services/index.d.ts +0 -0
- /package/{dist → src}/shared/services/translation.service.d.ts +0 -0
- /package/{dist → src}/shared/services/validator.service.d.ts +0 -0
- /package/{dist → src}/snake-naming.strategy.d.ts +0 -0
- /package/{dist → src}/types.d.ts +0 -0
- /package/{dist → src}/validators/file-mimetype.validator.d.ts +0 -0
- /package/{dist → src}/validators/index.d.ts +0 -0
- /package/{dist → src}/validators/is-exists.validator.d.ts +0 -0
- /package/{dist → src}/validators/is-unique.validator.d.ts +0 -0
- /package/{dist → src}/validators/phone-country-code.validator.d.ts +0 -0
- /package/{dist → src}/validators/same-as.validator.d.ts +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { isArray, isString, map } from 'lodash';
|
|
3
|
+
import type { TranslateOptions } from 'nestjs-i18n';
|
|
4
|
+
import { I18nService } from 'nestjs-i18n';
|
|
5
|
+
|
|
6
|
+
import { AbstractDto } from '../../common/dto/abstract.dto';
|
|
7
|
+
import { STATIC_TRANSLATION_DECORATOR_KEY } from '../../decorators';
|
|
8
|
+
import type { ITranslationDecoratorInterface } from '../../interfaces';
|
|
9
|
+
import { ContextProvider } from '../../providers';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class TranslationService {
|
|
13
|
+
constructor(private readonly i18n: I18nService) {}
|
|
14
|
+
|
|
15
|
+
async translate(key: string, options?: TranslateOptions): Promise<string> {
|
|
16
|
+
return this.i18n.translate(`${key}`, {
|
|
17
|
+
...options,
|
|
18
|
+
lang: ContextProvider.getLanguage(),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async translateNecessaryKeys<T extends AbstractDto>(dto: T): Promise<T> {
|
|
23
|
+
if (isString(dto)) {
|
|
24
|
+
return dto;
|
|
25
|
+
}
|
|
26
|
+
await Promise.all(
|
|
27
|
+
map(dto, async (value, key) => {
|
|
28
|
+
if (isString(value)) {
|
|
29
|
+
const translateDec: ITranslationDecoratorInterface | undefined =
|
|
30
|
+
Reflect.getMetadata(STATIC_TRANSLATION_DECORATOR_KEY, dto, key);
|
|
31
|
+
|
|
32
|
+
if (translateDec) {
|
|
33
|
+
return this.translate(
|
|
34
|
+
`${translateDec.translationKey ?? key}.${value}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (value instanceof AbstractDto) {
|
|
42
|
+
return this.translateNecessaryKeys(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isArray(value)) {
|
|
46
|
+
return Promise.all(
|
|
47
|
+
map(value, (v) => {
|
|
48
|
+
if (v instanceof AbstractDto) {
|
|
49
|
+
return this.translateNecessaryKeys(v);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return dto;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.ValidatorService = void 0;
|
|
42
|
+
const common_1 = require("@nestjs/common");
|
|
43
|
+
let ValidatorService = (() => {
|
|
44
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
var ValidatorService = _classThis = class {
|
|
49
|
+
isImage(mimeType) {
|
|
50
|
+
const imageMimeTypes = ['image/jpeg', 'image/png'];
|
|
51
|
+
return imageMimeTypes.includes(mimeType);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
__setFunctionName(_classThis, "ValidatorService");
|
|
55
|
+
(() => {
|
|
56
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
57
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
58
|
+
ValidatorService = _classThis = _classDescriptor.value;
|
|
59
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
60
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
61
|
+
})();
|
|
62
|
+
return ValidatorService = _classThis;
|
|
63
|
+
})();
|
|
64
|
+
exports.ValidatorService = ValidatorService;
|
|
@@ -8,11 +8,11 @@ class SnakeNamingStrategy extends typeorm_1.DefaultNamingStrategy {
|
|
|
8
8
|
if (className.includes('Entity')) {
|
|
9
9
|
className = className.replace('Entity', '');
|
|
10
10
|
}
|
|
11
|
-
return customName
|
|
11
|
+
return customName !== null && customName !== void 0 ? customName : (0, StringUtils_1.snakeCase)(className);
|
|
12
12
|
}
|
|
13
13
|
columnName(propertyName, customName, embeddedPrefixes) {
|
|
14
14
|
return ((0, StringUtils_1.snakeCase)(embeddedPrefixes.join('_')) +
|
|
15
|
-
(customName
|
|
15
|
+
(customName !== null && customName !== void 0 ? customName : (0, StringUtils_1.snakeCase)(propertyName)));
|
|
16
16
|
}
|
|
17
17
|
relationName(propertyName) {
|
|
18
18
|
return (0, StringUtils_1.snakeCase)(propertyName);
|
|
@@ -28,11 +28,10 @@ class SnakeNamingStrategy extends typeorm_1.DefaultNamingStrategy {
|
|
|
28
28
|
secondTableName);
|
|
29
29
|
}
|
|
30
30
|
joinTableColumnName(tableName, propertyName, columnName) {
|
|
31
|
-
return (0, StringUtils_1.snakeCase)(tableName + '_' + (columnName
|
|
31
|
+
return (0, StringUtils_1.snakeCase)(tableName + '_' + (columnName !== null && columnName !== void 0 ? columnName : propertyName));
|
|
32
32
|
}
|
|
33
33
|
classTableInheritanceParentColumnName(parentTableName, parentTableIdPropertyName) {
|
|
34
34
|
return (0, StringUtils_1.snakeCase)(`${parentTableName}_${parentTableIdPropertyName}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.SnakeNamingStrategy = SnakeNamingStrategy;
|
|
38
|
-
//# sourceMappingURL=snake-naming.strategy.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { NamingStrategyInterface } from 'typeorm';
|
|
2
|
+
import { DefaultNamingStrategy } from 'typeorm';
|
|
3
|
+
import { snakeCase } from 'typeorm/util/StringUtils';
|
|
4
|
+
|
|
5
|
+
export class SnakeNamingStrategy
|
|
6
|
+
extends DefaultNamingStrategy
|
|
7
|
+
implements NamingStrategyInterface
|
|
8
|
+
{
|
|
9
|
+
tableName(className: string, customName: string | undefined): string {
|
|
10
|
+
if (className.includes('Entity')) {
|
|
11
|
+
className = className.replace('Entity', '');
|
|
12
|
+
}
|
|
13
|
+
return customName ?? snakeCase(className);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
columnName(
|
|
17
|
+
propertyName: string,
|
|
18
|
+
customName: string | undefined,
|
|
19
|
+
embeddedPrefixes: string[],
|
|
20
|
+
): string {
|
|
21
|
+
return (
|
|
22
|
+
snakeCase(embeddedPrefixes.join('_')) +
|
|
23
|
+
(customName ?? snakeCase(propertyName))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
relationName(propertyName: string): string {
|
|
28
|
+
return snakeCase(propertyName);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
joinColumnName(relationName: string, referencedColumnName: string): string {
|
|
32
|
+
return snakeCase(relationName + '_' + referencedColumnName);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
joinTableName(
|
|
36
|
+
firstTableName: string,
|
|
37
|
+
secondTableName: string,
|
|
38
|
+
firstPropertyName: string,
|
|
39
|
+
_secondPropertyName: string,
|
|
40
|
+
): string {
|
|
41
|
+
return snakeCase(
|
|
42
|
+
firstTableName +
|
|
43
|
+
'_' +
|
|
44
|
+
firstPropertyName.replace(/\./gi, '_') +
|
|
45
|
+
'_' +
|
|
46
|
+
secondTableName,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
joinTableColumnName(
|
|
51
|
+
tableName: string,
|
|
52
|
+
propertyName: string,
|
|
53
|
+
columnName?: string,
|
|
54
|
+
): string {
|
|
55
|
+
return snakeCase(tableName + '_' + (columnName ?? propertyName));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
classTableInheritanceParentColumnName(
|
|
59
|
+
parentTableName: string,
|
|
60
|
+
parentTableIdPropertyName: string,
|
|
61
|
+
): string {
|
|
62
|
+
return snakeCase(`${parentTableName}_${parentTableIdPropertyName}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/{dist → src}/types.js
RENAMED
package/src/types.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
export type Constructor<T, Arguments extends unknown[] = undefined[]> = new (
|
|
3
|
+
...arguments_: Arguments
|
|
4
|
+
) => T;
|
|
5
|
+
|
|
6
|
+
export type Plain<T> = T;
|
|
7
|
+
|
|
8
|
+
export type PathImpl<T, Key extends keyof T> = Key extends string
|
|
9
|
+
? T[Key] extends Record<string, any>
|
|
10
|
+
?
|
|
11
|
+
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> &
|
|
12
|
+
string}`
|
|
13
|
+
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
|
|
14
|
+
: never
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
|
|
18
|
+
|
|
19
|
+
export type Path<T> = keyof T extends string
|
|
20
|
+
? PathImpl2<T> extends string | keyof T
|
|
21
|
+
? PathImpl2<T>
|
|
22
|
+
: keyof T
|
|
23
|
+
: never;
|
|
24
|
+
|
|
25
|
+
export type PathValue<
|
|
26
|
+
T,
|
|
27
|
+
P extends Path<T>,
|
|
28
|
+
> = P extends `${infer Key}.${infer Rest}`
|
|
29
|
+
? Key extends keyof T
|
|
30
|
+
? Rest extends Path<T[Key]>
|
|
31
|
+
? PathValue<T[Key], Rest>
|
|
32
|
+
: never
|
|
33
|
+
: never
|
|
34
|
+
: P extends keyof T
|
|
35
|
+
? T[P]
|
|
36
|
+
: never;
|
|
37
|
+
|
|
38
|
+
export type KeyOfType<Entity, U> = {
|
|
39
|
+
[P in keyof Required<Entity>]: Required<Entity>[P] extends U
|
|
40
|
+
? P
|
|
41
|
+
: Required<Entity>[P] extends U[]
|
|
42
|
+
? P
|
|
43
|
+
: never;
|
|
44
|
+
}[keyof Entity];
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FileMimetypeValidator = void 0;
|
|
4
4
|
const file_validator_interface_1 = require("@nestjs/common/pipes/file/file-validator.interface");
|
|
5
5
|
class FileMimetypeValidator extends file_validator_interface_1.FileValidator {
|
|
6
|
-
allowedMimetypes;
|
|
7
|
-
message;
|
|
8
6
|
constructor(options) {
|
|
9
7
|
super(options);
|
|
10
8
|
this.allowedMimetypes = options.allowedMimetypes;
|
|
@@ -21,4 +19,3 @@ class FileMimetypeValidator extends file_validator_interface_1.FileValidator {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
exports.FileMimetypeValidator = FileMimetypeValidator;
|
|
24
|
-
//# sourceMappingURL=file-mimetype.validator.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -17,4 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./phone-country-code.validator"), exports);
|
|
18
18
|
__exportStar(require("./skip-empty.validator"), exports);
|
|
19
19
|
__exportStar(require("./file-mimetype.validator"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.IsExists = exports.IsExistsValidator = void 0;
|
|
51
|
+
const class_validator_1 = require("class-validator");
|
|
52
|
+
const typeorm_transactional_1 = require("typeorm-transactional");
|
|
53
|
+
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
54
|
+
const common_1 = require("@nestjs/common");
|
|
55
|
+
let IsExistsValidator = (() => {
|
|
56
|
+
let _classDecorators = [(0, common_1.Injectable)(), (0, class_validator_1.ValidatorConstraint)({ name: 'isExists', async: true })];
|
|
57
|
+
let _classDescriptor;
|
|
58
|
+
let _classExtraInitializers = [];
|
|
59
|
+
let _classThis;
|
|
60
|
+
var IsExistsValidator = _classThis = class {
|
|
61
|
+
constructor(dataSource) {
|
|
62
|
+
this.dataSource = dataSource;
|
|
63
|
+
this.dataSource = (0, typeorm_transactional_1.getDataSourceByName)('default');
|
|
64
|
+
}
|
|
65
|
+
validate(value, args) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const [entityClass, findCondition] = args.constraints;
|
|
68
|
+
return ((yield this.dataSource.getRepository(entityClass).count({
|
|
69
|
+
where: findCondition(args),
|
|
70
|
+
})) > 0);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
defaultMessage(args) {
|
|
74
|
+
return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_EXISTS')(args);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__setFunctionName(_classThis, "IsExistsValidator");
|
|
78
|
+
(() => {
|
|
79
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
80
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
81
|
+
IsExistsValidator = _classThis = _classDescriptor.value;
|
|
82
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
83
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
84
|
+
})();
|
|
85
|
+
return IsExistsValidator = _classThis;
|
|
86
|
+
})();
|
|
87
|
+
exports.IsExistsValidator = IsExistsValidator;
|
|
88
|
+
function IsExists(constraints, validationOptions) {
|
|
89
|
+
return (object, propertyName) => {
|
|
90
|
+
(0, class_validator_1.registerDecorator)({
|
|
91
|
+
target: object.constructor,
|
|
92
|
+
propertyName,
|
|
93
|
+
options: validationOptions,
|
|
94
|
+
constraints,
|
|
95
|
+
validator: IsExistsValidator,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.IsExists = IsExists;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.IsUnique = exports.IsUniqueValidator = void 0;
|
|
51
|
+
const class_validator_1 = require("class-validator");
|
|
52
|
+
const typeorm_transactional_1 = require("typeorm-transactional");
|
|
53
|
+
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
54
|
+
let IsUniqueValidator = (() => {
|
|
55
|
+
let _classDecorators = [(0, class_validator_1.ValidatorConstraint)({ name: 'isUnique', async: true })];
|
|
56
|
+
let _classDescriptor;
|
|
57
|
+
let _classExtraInitializers = [];
|
|
58
|
+
let _classThis;
|
|
59
|
+
var IsUniqueValidator = _classThis = class {
|
|
60
|
+
constructor(dataSource) {
|
|
61
|
+
this.dataSource = dataSource;
|
|
62
|
+
this.dataSource = (0, typeorm_transactional_1.getDataSourceByName)('default');
|
|
63
|
+
}
|
|
64
|
+
validate(value, args) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const [entityClass, findCondition] = args.constraints;
|
|
67
|
+
let exists;
|
|
68
|
+
const defCon = findCondition(args);
|
|
69
|
+
const pkCols = this.dataSource
|
|
70
|
+
.getMetadata(entityClass)
|
|
71
|
+
.primaryColumns.map((column) => column.propertyName);
|
|
72
|
+
const isNew = pkCols.some((pk) => args.object[pk]);
|
|
73
|
+
if (!isNew) {
|
|
74
|
+
exists =
|
|
75
|
+
(yield this.dataSource
|
|
76
|
+
.getRepository(entityClass)
|
|
77
|
+
.count({ where: defCon })) < 1;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const entities = yield this.dataSource
|
|
81
|
+
.getRepository(entityClass)
|
|
82
|
+
.createQueryBuilder()
|
|
83
|
+
.where(defCon)
|
|
84
|
+
.select(pkCols)
|
|
85
|
+
.limit(2)
|
|
86
|
+
.execute();
|
|
87
|
+
const entityCount = entities.length;
|
|
88
|
+
if (entityCount === 1) {
|
|
89
|
+
const entity = entities[0];
|
|
90
|
+
const oldPk = {};
|
|
91
|
+
const newPk = {};
|
|
92
|
+
pkCols.map((pk) => {
|
|
93
|
+
oldPk[pk] = entity[pk];
|
|
94
|
+
newPk[pk] = args.object[pk];
|
|
95
|
+
});
|
|
96
|
+
exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
exists = entityCount < 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return exists;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
defaultMessage(args) {
|
|
106
|
+
return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_UNIQUE')(args);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__setFunctionName(_classThis, "IsUniqueValidator");
|
|
110
|
+
(() => {
|
|
111
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
112
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
113
|
+
IsUniqueValidator = _classThis = _classDescriptor.value;
|
|
114
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
115
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
116
|
+
})();
|
|
117
|
+
return IsUniqueValidator = _classThis;
|
|
118
|
+
})();
|
|
119
|
+
exports.IsUniqueValidator = IsUniqueValidator;
|
|
120
|
+
function IsUnique(constraints, validationOptions) {
|
|
121
|
+
return function (object, propertyName) {
|
|
122
|
+
(0, class_validator_1.registerDecorator)({
|
|
123
|
+
target: object.constructor,
|
|
124
|
+
propertyName,
|
|
125
|
+
options: validationOptions,
|
|
126
|
+
constraints,
|
|
127
|
+
validator: IsUniqueValidator,
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
exports.IsUnique = IsUnique;
|