@nest-omni/core 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/{src → dist}/boilerplate.polyfill.js +0 -1
  2. package/{src → dist}/common/abstract-client.service.d.ts +0 -4
  3. package/{src → dist}/common/abstract-client.service.js +0 -4
  4. package/{src → dist}/common/abstract.entity.d.ts +0 -7
  5. package/dist/common/abstract.entity.js +64 -0
  6. package/dist/common/dto/abstract.dto.js +59 -0
  7. package/dist/common/dto/bulk-id.dto.js +27 -0
  8. package/dist/common/dto/create-translation.dto.js +25 -0
  9. package/dist/common/dto/page-meta.dto.js +48 -0
  10. package/dist/common/dto/page-options.dto.js +52 -0
  11. package/dist/common/dto/page.dto.js +53 -0
  12. package/{src → dist}/common/utils.d.ts +0 -11
  13. package/{src → dist}/common/utils.js +1 -15
  14. package/{src → dist}/constants/language-code.js +0 -1
  15. package/dist/decorators/controller.decorator.js +11 -0
  16. package/{src → dist}/decorators/field.decorators.js +1 -7
  17. package/{src → dist}/decorators/omni-auth.decorator.js +1 -26
  18. package/{src → dist}/decorators/property.decorators.js +1 -5
  19. package/{src → dist}/decorators/public-route.decorator.js +0 -1
  20. package/{src → dist}/decorators/swagger.schema.js +1 -4
  21. package/{src → dist}/decorators/timestamp-column.decorator.js +1 -1
  22. package/dist/decorators/transform.decorators.d.ts +8 -0
  23. package/{src → dist}/decorators/transform.decorators.js +0 -27
  24. package/{src → dist}/decorators/translate.decorator.js +0 -1
  25. package/dist/decorators/user-check.decorator.js +21 -0
  26. package/{src → dist}/decorators/user.decorator.js +1 -25
  27. package/dist/filters/bad-request.filter.js +60 -0
  28. package/{src → dist}/filters/constraint-errors.js +0 -1
  29. package/dist/filters/query-failed.filter.js +42 -0
  30. package/dist/health-checker/health-checker.controller.js +72 -0
  31. package/dist/health-checker/health-checker.module.js +25 -0
  32. package/dist/health-checker/health-indicators/service.indicator.js +66 -0
  33. package/dist/helpers/common.helper.d.ts +3 -0
  34. package/{src → dist}/helpers/common.helper.js +0 -13
  35. package/{src → dist}/helpers/date.helper.d.ts +3 -3
  36. package/{src → dist}/helpers/date.helper.js +2 -25
  37. package/dist/i18n/en_US/validation.json +38 -0
  38. package/dist/i18n/zh_CN/validation.json +38 -0
  39. package/{src → dist}/index.js +0 -1
  40. package/dist/interceptors/auth-user.interceptor.js +24 -0
  41. package/dist/interceptors/language-interceptor.service.js +30 -0
  42. package/dist/interceptors/translation-interceptor.service.js +34 -0
  43. package/{src → dist}/providers/context.provider.js +0 -2
  44. package/{src → dist}/providers/generator.provider.d.ts +0 -4
  45. package/{src → dist}/providers/generator.provider.js +0 -4
  46. package/{src → dist}/setup/bootstrap.setup.js +7 -33
  47. package/dist/shared/serviceRegistryModule.js +110 -0
  48. package/{src → dist}/shared/services/api-config.service.d.ts +0 -3
  49. package/dist/shared/services/api-config.service.js +290 -0
  50. package/dist/shared/services/aws-s3.service.js +56 -0
  51. package/dist/shared/services/generator.service.js +23 -0
  52. package/dist/shared/services/translation.service.js +70 -0
  53. package/dist/shared/services/validator.service.js +20 -0
  54. package/dist/tsconfig.tsbuildinfo +1 -0
  55. package/dist/validators/is-exists.validator.js +61 -0
  56. package/dist/validators/is-unique.validator.js +92 -0
  57. package/{src → dist}/validators/skip-empty.validator.d.ts +0 -5
  58. package/{src → dist}/validators/skip-empty.validator.js +0 -5
  59. package/package.json +4 -1
  60. package/src/boilerplate.polyfill.ts +0 -202
  61. package/src/common/abstract-client.service.ts +0 -56
  62. package/src/common/abstract.entity.js +0 -152
  63. package/src/common/abstract.entity.ts +0 -73
  64. package/src/common/dto/abstract.dto.js +0 -96
  65. package/src/common/dto/abstract.dto.ts +0 -64
  66. package/src/common/dto/bulk-id.dto.js +0 -63
  67. package/src/common/dto/bulk-id.dto.ts +0 -13
  68. package/src/common/dto/create-translation.dto.js +0 -63
  69. package/src/common/dto/create-translation.dto.ts +0 -10
  70. package/src/common/dto/page-meta.dto.js +0 -88
  71. package/src/common/dto/page-meta.dto.ts +0 -37
  72. package/src/common/dto/page-options.dto.js +0 -87
  73. package/src/common/dto/page-options.dto.ts +0 -35
  74. package/src/common/dto/page.dto.js +0 -94
  75. package/src/common/dto/page.dto.ts +0 -36
  76. package/src/common/utils.ts +0 -45
  77. package/src/constants/index.ts +0 -4
  78. package/src/constants/language-code.ts +0 -7
  79. package/src/constants/order.ts +0 -4
  80. package/src/constants/role-type.ts +0 -4
  81. package/src/constants/token-type.ts +0 -4
  82. package/src/decorators/api-page-ok-response.decorator.ts +0 -31
  83. package/src/decorators/auth-user.decorator.ts +0 -16
  84. package/src/decorators/controller.decorator.js +0 -34
  85. package/src/decorators/controller.decorator.ts +0 -8
  86. package/src/decorators/field.decorators.ts +0 -773
  87. package/src/decorators/http.decorators.ts +0 -10
  88. package/src/decorators/index.ts +0 -12
  89. package/src/decorators/omni-auth.decorator.ts +0 -46
  90. package/src/decorators/operation.decorator.ts +0 -4
  91. package/src/decorators/property.decorators.ts +0 -62
  92. package/src/decorators/public-route.decorator.ts +0 -8
  93. package/src/decorators/swagger.schema.ts +0 -117
  94. package/src/decorators/timestamp-column.decorator.ts +0 -29
  95. package/src/decorators/transform.decorators.d.ts +0 -35
  96. package/src/decorators/transform.decorators.ts +0 -147
  97. package/src/decorators/translate.decorator.ts +0 -19
  98. package/src/decorators/use-dto.decorator.ts +0 -11
  99. package/src/decorators/user-check.decorator.js +0 -44
  100. package/src/decorators/user-check.decorator.ts +0 -30
  101. package/src/decorators/user.decorator.ts +0 -48
  102. package/src/decorators/user_auth.decorator.ts +0 -15
  103. package/src/decorators/validator.decorators.ts +0 -78
  104. package/src/exceptions/file-not-image.exception.ts +0 -7
  105. package/src/exceptions/index.ts +0 -2
  106. package/src/exceptions/page-type.exception.ts +0 -7
  107. package/src/exceptions/user-not-found.exception.ts +0 -7
  108. package/src/filters/bad-request.filter.js +0 -104
  109. package/src/filters/bad-request.filter.ts +0 -67
  110. package/src/filters/constraint-errors.ts +0 -5
  111. package/src/filters/index.ts +0 -3
  112. package/src/filters/query-failed.filter.js +0 -81
  113. package/src/filters/query-failed.filter.ts +0 -32
  114. package/src/health-checker/health-checker.controller.js +0 -104
  115. package/src/health-checker/health-checker.controller.ts +0 -51
  116. package/src/health-checker/health-checker.module.js +0 -69
  117. package/src/health-checker/health-checker.module.ts +0 -13
  118. package/src/health-checker/health-indicators/service.indicator.js +0 -102
  119. package/src/health-checker/health-indicators/service.indicator.ts +0 -44
  120. package/src/helpers/common.helper.d.ts +0 -16
  121. package/src/helpers/common.helper.ts +0 -49
  122. package/src/helpers/date.helper.ts +0 -64
  123. package/src/helpers/excel.helper.d.ts +0 -27
  124. package/src/helpers/excel.helper.js +0 -338
  125. package/src/helpers/index.ts +0 -3
  126. package/src/i18n/en_US/validation.json +0 -38
  127. package/src/i18n/zh_CN/validation.json +0 -38
  128. package/src/index.ts +0 -12
  129. package/src/interceptors/auth-user.interceptor.js +0 -68
  130. package/src/interceptors/auth-user.interceptor.ts +0 -20
  131. package/src/interceptors/index.ts +0 -2
  132. package/src/interceptors/language-interceptor.service.js +0 -74
  133. package/src/interceptors/language-interceptor.service.ts +0 -31
  134. package/src/interceptors/translation-interceptor.service.js +0 -83
  135. package/src/interceptors/translation-interceptor.service.ts +0 -43
  136. package/src/interfaces/IApiFile.ts +0 -4
  137. package/src/interfaces/IFile.ts +0 -8
  138. package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
  139. package/src/interfaces/index.ts +0 -3
  140. package/src/interfaces/response.ts +0 -37
  141. package/src/middlewares/index.ts +0 -3
  142. package/src/middlewares/omni-auth.middleware.ts +0 -10
  143. package/src/middlewares/powerby.middleware.ts +0 -6
  144. package/src/middlewares/request-id.middleware.ts +0 -28
  145. package/src/providers/context.provider.ts +0 -98
  146. package/src/providers/generator.provider.ts +0 -66
  147. package/src/providers/index.ts +0 -2
  148. package/src/setup/bootstrap.setup.ts +0 -139
  149. package/src/setup/index.ts +0 -1
  150. package/src/setup/microservices.setup.js +0 -55
  151. package/src/setup-swagger.ts +0 -67
  152. package/src/shared/index.ts +0 -2
  153. package/src/shared/serviceRegistryModule.js +0 -176
  154. package/src/shared/serviceRegistryModule.ts +0 -110
  155. package/src/shared/services/api-config.service.js +0 -335
  156. package/src/shared/services/api-config.service.ts +0 -319
  157. package/src/shared/services/aws-s3.service.js +0 -96
  158. package/src/shared/services/aws-s3.service.ts +0 -39
  159. package/src/shared/services/generator.service.js +0 -67
  160. package/src/shared/services/generator.service.ts +0 -13
  161. package/src/shared/services/index.ts +0 -5
  162. package/src/shared/services/translation.service.js +0 -109
  163. package/src/shared/services/translation.service.ts +0 -59
  164. package/src/shared/services/validator.service.js +0 -64
  165. package/src/shared/services/validator.service.ts +0 -10
  166. package/src/snake-naming.strategy.ts +0 -64
  167. package/src/types.ts +0 -44
  168. package/src/validators/file-mimetype.validator.ts +0 -34
  169. package/src/validators/index.ts +0 -3
  170. package/src/validators/is-exists.validator.js +0 -99
  171. package/src/validators/is-exists.validator.ts +0 -60
  172. package/src/validators/is-unique.validator.js +0 -131
  173. package/src/validators/is-unique.validator.ts +0 -93
  174. package/src/validators/phone-country-code.validator.ts +0 -36
  175. package/src/validators/same-as.validator.ts +0 -27
  176. package/src/validators/skip-empty.validator.ts +0 -25
  177. package/tsconfig.json +0 -26
  178. package/tsconfig.lib.json +0 -16
  179. package/tsconfig.tsbuildinfo +0 -1
  180. /package/{src → dist}/boilerplate.polyfill.d.ts +0 -0
  181. /package/{src → dist}/common/dto/abstract.dto.d.ts +0 -0
  182. /package/{src → dist}/common/dto/bulk-id.dto.d.ts +0 -0
  183. /package/{src → dist}/common/dto/create-translation.dto.d.ts +0 -0
  184. /package/{src → dist}/common/dto/page-meta.dto.d.ts +0 -0
  185. /package/{src → dist}/common/dto/page-options.dto.d.ts +0 -0
  186. /package/{src → dist}/common/dto/page.dto.d.ts +0 -0
  187. /package/{src → dist}/constants/index.d.ts +0 -0
  188. /package/{src → dist}/constants/index.js +0 -0
  189. /package/{src → dist}/constants/language-code.d.ts +0 -0
  190. /package/{src → dist}/constants/order.d.ts +0 -0
  191. /package/{src → dist}/constants/order.js +0 -0
  192. /package/{src → dist}/constants/role-type.d.ts +0 -0
  193. /package/{src → dist}/constants/role-type.js +0 -0
  194. /package/{src → dist}/constants/token-type.d.ts +0 -0
  195. /package/{src → dist}/constants/token-type.js +0 -0
  196. /package/{src → dist}/decorators/api-page-ok-response.decorator.d.ts +0 -0
  197. /package/{src → dist}/decorators/api-page-ok-response.decorator.js +0 -0
  198. /package/{src → dist}/decorators/auth-user.decorator.d.ts +0 -0
  199. /package/{src → dist}/decorators/auth-user.decorator.js +0 -0
  200. /package/{src → dist}/decorators/controller.decorator.d.ts +0 -0
  201. /package/{src → dist}/decorators/field.decorators.d.ts +0 -0
  202. /package/{src → dist}/decorators/http.decorators.d.ts +0 -0
  203. /package/{src → dist}/decorators/http.decorators.js +0 -0
  204. /package/{src → dist}/decorators/index.d.ts +0 -0
  205. /package/{src → dist}/decorators/index.js +0 -0
  206. /package/{src → dist}/decorators/omni-auth.decorator.d.ts +0 -0
  207. /package/{src → dist}/decorators/operation.decorator.d.ts +0 -0
  208. /package/{src → dist}/decorators/operation.decorator.js +0 -0
  209. /package/{src → dist}/decorators/property.decorators.d.ts +0 -0
  210. /package/{src → dist}/decorators/public-route.decorator.d.ts +0 -0
  211. /package/{src → dist}/decorators/swagger.schema.d.ts +0 -0
  212. /package/{src → dist}/decorators/timestamp-column.decorator.d.ts +0 -0
  213. /package/{src → dist}/decorators/translate.decorator.d.ts +0 -0
  214. /package/{src → dist}/decorators/use-dto.decorator.d.ts +0 -0
  215. /package/{src → dist}/decorators/use-dto.decorator.js +0 -0
  216. /package/{src → dist}/decorators/user-check.decorator.d.ts +0 -0
  217. /package/{src → dist}/decorators/user.decorator.d.ts +0 -0
  218. /package/{src → dist}/decorators/user_auth.decorator.d.ts +0 -0
  219. /package/{src → dist}/decorators/user_auth.decorator.js +0 -0
  220. /package/{src → dist}/decorators/validator.decorators.d.ts +0 -0
  221. /package/{src → dist}/decorators/validator.decorators.js +0 -0
  222. /package/{src → dist}/exceptions/file-not-image.exception.d.ts +0 -0
  223. /package/{src → dist}/exceptions/file-not-image.exception.js +0 -0
  224. /package/{src → dist}/exceptions/index.d.ts +0 -0
  225. /package/{src → dist}/exceptions/index.js +0 -0
  226. /package/{src → dist}/exceptions/page-type.exception.d.ts +0 -0
  227. /package/{src → dist}/exceptions/page-type.exception.js +0 -0
  228. /package/{src → dist}/exceptions/user-not-found.exception.d.ts +0 -0
  229. /package/{src → dist}/exceptions/user-not-found.exception.js +0 -0
  230. /package/{src → dist}/filters/bad-request.filter.d.ts +0 -0
  231. /package/{src → dist}/filters/constraint-errors.d.ts +0 -0
  232. /package/{src → dist}/filters/index.d.ts +0 -0
  233. /package/{src → dist}/filters/index.js +0 -0
  234. /package/{src → dist}/filters/query-failed.filter.d.ts +0 -0
  235. /package/{src → dist}/health-checker/health-checker.controller.d.ts +0 -0
  236. /package/{src → dist}/health-checker/health-checker.module.d.ts +0 -0
  237. /package/{src → dist}/health-checker/health-indicators/service.indicator.d.ts +0 -0
  238. /package/{src → dist}/helpers/index.d.ts +0 -0
  239. /package/{src → dist}/helpers/index.js +0 -0
  240. /package/{src → dist}/index.d.ts +0 -0
  241. /package/{src → dist}/interceptors/auth-user.interceptor.d.ts +0 -0
  242. /package/{src → dist}/interceptors/index.d.ts +0 -0
  243. /package/{src → dist}/interceptors/index.js +0 -0
  244. /package/{src → dist}/interceptors/language-interceptor.service.d.ts +0 -0
  245. /package/{src → dist}/interceptors/translation-interceptor.service.d.ts +0 -0
  246. /package/{src → dist}/interfaces/IApiFile.d.ts +0 -0
  247. /package/{src → dist}/interfaces/IApiFile.js +0 -0
  248. /package/{src → dist}/interfaces/IFile.d.ts +0 -0
  249. /package/{src → dist}/interfaces/IFile.js +0 -0
  250. /package/{src → dist}/interfaces/ITranslationDecoratorInterface.d.ts +0 -0
  251. /package/{src → dist}/interfaces/ITranslationDecoratorInterface.js +0 -0
  252. /package/{src → dist}/interfaces/index.d.ts +0 -0
  253. /package/{src → dist}/interfaces/index.js +0 -0
  254. /package/{src → dist}/interfaces/response.d.ts +0 -0
  255. /package/{src → dist}/interfaces/response.js +0 -0
  256. /package/{src → dist}/middlewares/index.d.ts +0 -0
  257. /package/{src → dist}/middlewares/index.js +0 -0
  258. /package/{src → dist}/middlewares/omni-auth.middleware.d.ts +0 -0
  259. /package/{src → dist}/middlewares/omni-auth.middleware.js +0 -0
  260. /package/{src → dist}/middlewares/powerby.middleware.d.ts +0 -0
  261. /package/{src → dist}/middlewares/powerby.middleware.js +0 -0
  262. /package/{src → dist}/middlewares/request-id.middleware.d.ts +0 -0
  263. /package/{src → dist}/middlewares/request-id.middleware.js +0 -0
  264. /package/{src → dist}/providers/context.provider.d.ts +0 -0
  265. /package/{src → dist}/providers/index.d.ts +0 -0
  266. /package/{src → dist}/providers/index.js +0 -0
  267. /package/{src → dist}/setup/bootstrap.setup.d.ts +0 -0
  268. /package/{src → dist}/setup/index.d.ts +0 -0
  269. /package/{src → dist}/setup/index.js +0 -0
  270. /package/{src → dist}/setup-swagger.d.ts +0 -0
  271. /package/{src → dist}/setup-swagger.js +0 -0
  272. /package/{src → dist}/shared/index.d.ts +0 -0
  273. /package/{src → dist}/shared/index.js +0 -0
  274. /package/{src → dist}/shared/serviceRegistryModule.d.ts +0 -0
  275. /package/{src → dist}/shared/services/aws-s3.service.d.ts +0 -0
  276. /package/{src → dist}/shared/services/generator.service.d.ts +0 -0
  277. /package/{src → dist}/shared/services/index.d.ts +0 -0
  278. /package/{src → dist}/shared/services/index.js +0 -0
  279. /package/{src → dist}/shared/services/translation.service.d.ts +0 -0
  280. /package/{src → dist}/shared/services/validator.service.d.ts +0 -0
  281. /package/{src → dist}/snake-naming.strategy.d.ts +0 -0
  282. /package/{src → dist}/snake-naming.strategy.js +0 -0
  283. /package/{src → dist}/types.d.ts +0 -0
  284. /package/{src → dist}/types.js +0 -0
  285. /package/{src → dist}/validators/file-mimetype.validator.d.ts +0 -0
  286. /package/{src → dist}/validators/file-mimetype.validator.js +0 -0
  287. /package/{src → dist}/validators/index.d.ts +0 -0
  288. /package/{src → dist}/validators/index.js +0 -0
  289. /package/{src → dist}/validators/is-exists.validator.d.ts +0 -0
  290. /package/{src → dist}/validators/is-unique.validator.d.ts +0 -0
  291. /package/{src → dist}/validators/phone-country-code.validator.d.ts +0 -0
  292. /package/{src → dist}/validators/phone-country-code.validator.js +0 -0
  293. /package/{src → dist}/validators/same-as.validator.d.ts +0 -0
  294. /package/{src → dist}/validators/same-as.validator.js +0 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.IsExists = exports.IsExistsValidator = void 0;
22
+ const class_validator_1 = require("class-validator");
23
+ const typeorm_1 = require("typeorm");
24
+ const typeorm_transactional_1 = require("typeorm-transactional");
25
+ const nestjs_i18n_1 = require("nestjs-i18n");
26
+ const common_1 = require("@nestjs/common");
27
+ let IsExistsValidator = class IsExistsValidator {
28
+ constructor(dataSource) {
29
+ this.dataSource = dataSource;
30
+ this.dataSource = (0, typeorm_transactional_1.getDataSourceByName)('default');
31
+ }
32
+ validate(value, args) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const [entityClass, findCondition] = args.constraints;
35
+ return ((yield this.dataSource.getRepository(entityClass).count({
36
+ where: findCondition(args),
37
+ })) > 0);
38
+ });
39
+ }
40
+ defaultMessage(args) {
41
+ return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_EXISTS')(args);
42
+ }
43
+ };
44
+ exports.IsExistsValidator = IsExistsValidator;
45
+ exports.IsExistsValidator = IsExistsValidator = __decorate([
46
+ (0, common_1.Injectable)(),
47
+ (0, class_validator_1.ValidatorConstraint)({ name: 'isExists', async: true }),
48
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
49
+ ], IsExistsValidator);
50
+ function IsExists(constraints, validationOptions) {
51
+ return (object, propertyName) => {
52
+ (0, class_validator_1.registerDecorator)({
53
+ target: object.constructor,
54
+ propertyName,
55
+ options: validationOptions,
56
+ constraints,
57
+ validator: IsExistsValidator,
58
+ });
59
+ };
60
+ }
61
+ exports.IsExists = IsExists;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.IsUnique = exports.IsUniqueValidator = void 0;
22
+ const class_validator_1 = require("class-validator");
23
+ const typeorm_1 = require("typeorm");
24
+ const typeorm_transactional_1 = require("typeorm-transactional");
25
+ const nestjs_i18n_1 = require("nestjs-i18n");
26
+ let IsUniqueValidator = class IsUniqueValidator {
27
+ constructor(dataSource) {
28
+ this.dataSource = dataSource;
29
+ this.dataSource = (0, typeorm_transactional_1.getDataSourceByName)('default');
30
+ }
31
+ validate(value, args) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const [entityClass, findCondition] = args.constraints;
34
+ let exists;
35
+ const defCon = findCondition(args);
36
+ const pkCols = this.dataSource
37
+ .getMetadata(entityClass)
38
+ .primaryColumns.map((column) => column.propertyName);
39
+ const isNew = pkCols.some((pk) => args.object[pk]);
40
+ if (!isNew) {
41
+ exists =
42
+ (yield this.dataSource
43
+ .getRepository(entityClass)
44
+ .count({ where: defCon })) < 1;
45
+ }
46
+ else {
47
+ const entities = yield this.dataSource
48
+ .getRepository(entityClass)
49
+ .createQueryBuilder()
50
+ .where(defCon)
51
+ .select(pkCols)
52
+ .limit(2)
53
+ .execute();
54
+ const entityCount = entities.length;
55
+ if (entityCount === 1) {
56
+ const entity = entities[0];
57
+ const oldPk = {};
58
+ const newPk = {};
59
+ pkCols.map((pk) => {
60
+ oldPk[pk] = entity[pk];
61
+ newPk[pk] = args.object[pk];
62
+ });
63
+ exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
64
+ }
65
+ else {
66
+ exists = entityCount < 1;
67
+ }
68
+ }
69
+ return exists;
70
+ });
71
+ }
72
+ defaultMessage(args) {
73
+ return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_UNIQUE')(args);
74
+ }
75
+ };
76
+ exports.IsUniqueValidator = IsUniqueValidator;
77
+ exports.IsUniqueValidator = IsUniqueValidator = __decorate([
78
+ (0, class_validator_1.ValidatorConstraint)({ name: 'isUnique', async: true }),
79
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
80
+ ], IsUniqueValidator);
81
+ function IsUnique(constraints, validationOptions) {
82
+ return function (object, propertyName) {
83
+ (0, class_validator_1.registerDecorator)({
84
+ target: object.constructor,
85
+ propertyName,
86
+ options: validationOptions,
87
+ constraints,
88
+ validator: IsUniqueValidator,
89
+ });
90
+ };
91
+ }
92
+ exports.IsUnique = IsUnique;
@@ -1,6 +1 @@
1
- /**
2
- * When the value is emtpy, validation is skipped
3
- * @param field
4
- * @constructor
5
- */
6
1
  export declare function SkipEmpty(field?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -5,11 +5,6 @@ const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const class_validator_1 = require("class-validator");
7
7
  const lodash_1 = require("lodash");
8
- /**
9
- * When the value is emtpy, validation is skipped
10
- * @param field
11
- * @constructor
12
- */
13
8
  function SkipEmpty(field) {
14
9
  return (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({ required: false }), (0, class_validator_1.ValidateIf)((obj, value) => {
15
10
  if (field) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-omni/core",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,6 +17,9 @@
17
17
  "devDependencies": {
18
18
  "typescript": "^5.4.5"
19
19
  },
20
+ "files": [
21
+ "dist"
22
+ ],
20
23
  "dependencies": {
21
24
  "@dataui/crud": "^5.3.0",
22
25
  "@dataui/crud-typeorm": "^5.3.0",
@@ -1,202 +0,0 @@
1
- import 'source-map-support/register';
2
-
3
- import { compact, map } from 'lodash';
4
- import type { ObjectLiteral } from 'typeorm';
5
- import { Brackets, SelectQueryBuilder } from 'typeorm';
6
-
7
- import type { AbstractEntity } from './common/abstract.entity';
8
- import type { AbstractDto } from './common/dto/abstract.dto';
9
- import type { CreateTranslationDto } from './common/dto/create-translation.dto';
10
- import { PageDto } from './common/dto/page.dto';
11
- import { PageMetaDto } from './common/dto/page-meta.dto';
12
- import type { PageOptionsDto } from './common/dto/page-options.dto';
13
- import type { LanguageCode } from './constants/language-code';
14
- import type { KeyOfType } from './types';
15
- import { ContextProvider } from './providers';
16
-
17
- declare global {
18
- export type Uuid = string & { _uuidBrand: undefined };
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-redundant-type-constituents
20
- export type Todo = any & { _todoBrand: undefined };
21
-
22
- // eslint-disable-next-line @typescript-eslint/naming-convention
23
- interface Array<T> {
24
- toDtos<Dto extends AbstractDto>(this: T[], options?: unknown): Dto[];
25
-
26
- getByLanguage(
27
- this: CreateTranslationDto[],
28
- languageCode: LanguageCode,
29
- ): string;
30
-
31
- toPageDto<Dto extends AbstractDto>(
32
- this: T[],
33
- pageMetaDto: PageMetaDto,
34
- // FIXME make option type visible from entity
35
- options?: unknown,
36
- ): PageDto<Dto>;
37
- }
38
- }
39
-
40
- declare module 'typeorm' {
41
- // eslint-disable-next-line @typescript-eslint/naming-convention
42
- interface SelectQueryBuilder<Entity> {
43
- searchByString(
44
- q: string,
45
- columnNames: string[],
46
- options?: {
47
- formStart: boolean;
48
- },
49
- ): this;
50
-
51
- withTenant(tenantId?: string | number, tenantFieldName?: string): this;
52
-
53
- paginate(
54
- this: SelectQueryBuilder<Entity>,
55
- pageOptionsDto: PageOptionsDto,
56
- options?: Partial<{ takeAll: boolean; skipCount: boolean }>,
57
- ): Promise<[Entity[], PageMetaDto]>;
58
-
59
- leftJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
60
- this: SelectQueryBuilder<Entity>,
61
- property: `${A}.${Exclude<
62
- KeyOfType<AliasEntity, AbstractEntity>,
63
- symbol
64
- >}`,
65
- alias: string,
66
- condition?: string,
67
- parameters?: ObjectLiteral,
68
- ): this;
69
-
70
- leftJoin<AliasEntity extends AbstractEntity, A extends string>(
71
- this: SelectQueryBuilder<Entity>,
72
- property: `${A}.${Exclude<
73
- KeyOfType<AliasEntity, AbstractEntity>,
74
- symbol
75
- >}`,
76
- alias: string,
77
- condition?: string,
78
- parameters?: ObjectLiteral,
79
- ): this;
80
-
81
- innerJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
82
- this: SelectQueryBuilder<Entity>,
83
- property: `${A}.${Exclude<
84
- KeyOfType<AliasEntity, AbstractEntity>,
85
- symbol
86
- >}`,
87
- alias: string,
88
- condition?: string,
89
- parameters?: ObjectLiteral,
90
- ): this;
91
-
92
- innerJoin<AliasEntity extends AbstractEntity, A extends string>(
93
- this: SelectQueryBuilder<Entity>,
94
- property: `${A}.${Exclude<
95
- KeyOfType<AliasEntity, AbstractEntity>,
96
- symbol
97
- >}`,
98
- alias: string,
99
- condition?: string,
100
- parameters?: ObjectLiteral,
101
- ): this;
102
- }
103
- }
104
-
105
- Array.prototype.toDtos = function <
106
- Entity extends AbstractEntity<Dto>,
107
- Dto extends AbstractDto,
108
- >(options?: unknown): Dto[] {
109
- return compact(
110
- map<Entity, Dto>(this as Entity[], (item) => item.toDto(options as never)),
111
- );
112
- };
113
-
114
- Array.prototype.getByLanguage = function (languageCode: LanguageCode): string {
115
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
116
- return this.find((translation) => languageCode === translation.languageCode)!
117
- .text;
118
- };
119
-
120
- Array.prototype.toPageDto = function (
121
- pageMetaDto: PageMetaDto,
122
- options?: unknown,
123
- ) {
124
- return new PageDto(this.toDtos(options), pageMetaDto);
125
- };
126
-
127
- SelectQueryBuilder.prototype.searchByString = function (
128
- q,
129
- columnNames,
130
- options,
131
- ) {
132
- if (!q) {
133
- return this;
134
- }
135
-
136
- this.andWhere(
137
- new Brackets((qb) => {
138
- for (const item of columnNames) {
139
- qb.orWhere(`${item} ILIKE :q`);
140
- }
141
- }),
142
- );
143
-
144
- if (options?.formStart) {
145
- this.setParameter('q', `${q}%`);
146
- } else {
147
- this.setParameter('q', `%${q}%`);
148
- }
149
-
150
- return this;
151
- };
152
-
153
- SelectQueryBuilder.prototype.paginate = async function (
154
- pageOptionsDto: PageOptionsDto,
155
- options?: Partial<{
156
- skipCount: boolean;
157
- takeAll: boolean;
158
- }>,
159
- ) {
160
- if (!options?.takeAll) {
161
- this.skip(pageOptionsDto.skip).take(pageOptionsDto.pageSize);
162
- }
163
-
164
- const entities = await this.getMany();
165
-
166
- let itemCount = -1;
167
-
168
- if (!options?.skipCount) {
169
- itemCount = await this.getCount();
170
- }
171
-
172
- const pageMetaDto = new PageMetaDto({
173
- itemCount,
174
- pageOptionsDto,
175
- });
176
-
177
- return [entities, pageMetaDto];
178
- };
179
-
180
- SelectQueryBuilder.prototype.withTenant = function (
181
- tenantId?: number | string,
182
- tenantFieldName: string = 'tenantId',
183
- ) {
184
- if (!tenantId) {
185
- tenantId = ContextProvider.getTenantId();
186
- }
187
-
188
- if (this.expressionMap.mainAlias.hasMetadata) {
189
- const entityMetadata = this.expressionMap.mainAlias.metadata;
190
- const columnName = entityMetadata.columns.find(
191
- (column: any) => column.propertyName === tenantFieldName,
192
- )?.databaseName;
193
-
194
- if (columnName) {
195
- return this.andWhere(`${this.alias}.${columnName} = :tenantId`, {
196
- tenantId,
197
- });
198
- }
199
- }
200
-
201
- return this;
202
- };
@@ -1,56 +0,0 @@
1
- import type { ClientProxy } from '@nestjs/microservices';
2
- import { plainToInstance } from 'class-transformer';
3
- import { firstValueFrom } from 'rxjs';
4
-
5
- import { PageTypeException } from '../exceptions/page-type.exception';
6
- import type { Constructor } from '../types';
7
- import type { PageDto } from './dto/page.dto';
8
- import type { PageMetaDto } from './dto/page-meta.dto';
9
-
10
- /**
11
- * Fixme: This class designed to use with @nestjs/microservices by extending and creating a new class.
12
- * TODO: Create Implementation and usage of it
13
- */
14
- export class AbstractClientService<ActionType> {
15
- constructor(private client: ClientProxy) {}
16
-
17
- public async send(pattern: ActionType, data: unknown): Promise<void>;
18
-
19
- public async send<R>(
20
- pattern: ActionType,
21
- data: unknown,
22
- returnDataOptions: { class: Constructor<R>; isPage: true },
23
- ): Promise<PageDto<R>>;
24
-
25
- public async send<R>(
26
- pattern: ActionType,
27
- data: unknown,
28
- returnDataOptions?: { class: Constructor<R>; isPage?: false },
29
- ): Promise<R>;
30
-
31
- public async send<R, I>(
32
- pattern: ActionType,
33
- data: I,
34
- returnDataOptions?: Partial<{
35
- class?: Constructor<R>;
36
- isPage?: boolean;
37
- }>,
38
- ): Promise<R | PageDto<R> | void> {
39
- const returnData = await firstValueFrom(
40
- this.client.send<{ data?: R; meta?: PageMetaDto }>(pattern, data),
41
- {
42
- defaultValue: undefined,
43
- },
44
- );
45
-
46
- if (returnDataOptions?.isPage && (!returnData?.data || !returnData.meta)) {
47
- throw new PageTypeException();
48
- }
49
-
50
- if (!returnDataOptions?.class || returnDataOptions.isPage) {
51
- return returnData as R;
52
- }
53
-
54
- return plainToInstance(returnDataOptions.class, returnData);
55
- }
56
- }
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.AbstractStringPrimaryEntity = exports.AbstractTranslationEntity = exports.AbstractEntity = exports.AbstractBaseEntity = void 0;
38
- const typeorm_1 = require("typeorm");
39
- const decorators_1 = require("../decorators");
40
- const constants_1 = require("../constants");
41
- /**
42
- * Abstract Entity
43
- *
44
- * @description This class is an abstract class for all entities.
45
- * It's experimental and recommended using it only in microservice architecture,
46
- * otherwise just delete and use your own entity.
47
- */
48
- let AbstractBaseEntity = (() => {
49
- var _a;
50
- let _instanceExtraInitializers = [];
51
- let _createdAt_decorators;
52
- let _createdAt_initializers = [];
53
- let _updatedAt_decorators;
54
- let _updatedAt_initializers = [];
55
- return _a = class AbstractBaseEntity {
56
- constructor() {
57
- this.createdAt = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _createdAt_initializers, void 0));
58
- this.updatedAt = __runInitializers(this, _updatedAt_initializers, void 0);
59
- }
60
- toDto(options) {
61
- const dtoClass = Object.getPrototypeOf(this).dtoClass;
62
- if (!dtoClass) {
63
- throw new Error(`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`);
64
- }
65
- return new dtoClass(this, options);
66
- }
67
- },
68
- (() => {
69
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
70
- _createdAt_decorators = [(0, typeorm_1.CreateDateColumn)({
71
- type: 'timestamp',
72
- })];
73
- _updatedAt_decorators = [(0, typeorm_1.UpdateDateColumn)({
74
- type: 'timestamp',
75
- })];
76
- __esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _instanceExtraInitializers);
77
- __esDecorate(null, null, _updatedAt_decorators, { kind: "field", name: "updatedAt", static: false, private: false, access: { has: obj => "updatedAt" in obj, get: obj => obj.updatedAt, set: (obj, value) => { obj.updatedAt = value; } }, metadata: _metadata }, _updatedAt_initializers, _instanceExtraInitializers);
78
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
79
- })(),
80
- _a;
81
- })();
82
- exports.AbstractBaseEntity = AbstractBaseEntity;
83
- let AbstractEntity = (() => {
84
- var _a;
85
- let _classSuper = AbstractBaseEntity;
86
- let _instanceExtraInitializers = [];
87
- let _id_decorators;
88
- let _id_initializers = [];
89
- return _a = class AbstractEntity extends _classSuper {
90
- constructor() {
91
- super(...arguments);
92
- this.id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, void 0));
93
- }
94
- },
95
- (() => {
96
- var _b;
97
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
98
- _id_decorators = [(0, typeorm_1.PrimaryGeneratedColumn)('increment', { type: 'bigint' }), (0, decorators_1.NumberFieldOptional)({ swagger: false })];
99
- __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _instanceExtraInitializers);
100
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
101
- })(),
102
- _a;
103
- })();
104
- exports.AbstractEntity = AbstractEntity;
105
- let AbstractTranslationEntity = (() => {
106
- var _a;
107
- let _classSuper = AbstractEntity;
108
- let _instanceExtraInitializers = [];
109
- let _languageCode_decorators;
110
- let _languageCode_initializers = [];
111
- return _a = class AbstractTranslationEntity extends _classSuper {
112
- constructor() {
113
- super(...arguments);
114
- this.languageCode = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _languageCode_initializers, void 0));
115
- }
116
- },
117
- (() => {
118
- var _b;
119
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
120
- _languageCode_decorators = [(0, typeorm_1.Column)({ type: 'enum', enum: constants_1.LanguageCode })];
121
- __esDecorate(null, null, _languageCode_decorators, { kind: "field", name: "languageCode", static: false, private: false, access: { has: obj => "languageCode" in obj, get: obj => obj.languageCode, set: (obj, value) => { obj.languageCode = value; } }, metadata: _metadata }, _languageCode_initializers, _instanceExtraInitializers);
122
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
123
- })(),
124
- _a;
125
- })();
126
- exports.AbstractTranslationEntity = AbstractTranslationEntity;
127
- let AbstractStringPrimaryEntity = (() => {
128
- var _a;
129
- let _classSuper = AbstractBaseEntity;
130
- let _instanceExtraInitializers = [];
131
- let _id_decorators;
132
- let _id_initializers = [];
133
- return _a = class AbstractStringPrimaryEntity extends _classSuper {
134
- constructor() {
135
- super(...arguments);
136
- this.id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, void 0));
137
- }
138
- },
139
- (() => {
140
- var _b;
141
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
142
- _id_decorators = [(0, typeorm_1.PrimaryGeneratedColumn)('uuid'), (0, decorators_1.StringFieldOptional)({
143
- maxLength: 36,
144
- minLength: 2,
145
- example: '23247899-c237-4ab1-9639-3322029d2e1c',
146
- })];
147
- __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _instanceExtraInitializers);
148
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
149
- })(),
150
- _a;
151
- })();
152
- exports.AbstractStringPrimaryEntity = AbstractStringPrimaryEntity;
@@ -1,73 +0,0 @@
1
- import {
2
- Column,
3
- CreateDateColumn,
4
- PrimaryGeneratedColumn,
5
- UpdateDateColumn,
6
- } from 'typeorm';
7
-
8
- import type { AbstractDto, AbstractTranslationDto } from './dto/abstract.dto';
9
- import { NumberFieldOptional, StringFieldOptional } from '../decorators';
10
- import { LanguageCode } from '../constants';
11
-
12
- /**
13
- * Abstract Entity
14
- *
15
- * @description This class is an abstract class for all entities.
16
- * It's experimental and recommended using it only in microservice architecture,
17
- * otherwise just delete and use your own entity.
18
- */
19
- export abstract class AbstractBaseEntity<DTO, O> {
20
- @CreateDateColumn({
21
- type: 'timestamp',
22
- })
23
- createdAt: Date;
24
-
25
- @UpdateDateColumn({
26
- type: 'timestamp',
27
- })
28
- updatedAt: Date;
29
-
30
- translations?: AbstractTranslationEntity[];
31
-
32
- toDto(options?: O): DTO {
33
- const dtoClass = Object.getPrototypeOf(this).dtoClass;
34
-
35
- if (!dtoClass) {
36
- throw new Error(
37
- `You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`,
38
- );
39
- }
40
-
41
- return new dtoClass(this, options);
42
- }
43
- }
44
-
45
- export class AbstractEntity<
46
- DTO extends AbstractDto = AbstractDto,
47
- O = never,
48
- > extends AbstractBaseEntity<DTO, O> {
49
- @PrimaryGeneratedColumn('increment', { type: 'bigint' })
50
- @NumberFieldOptional({ swagger: false })
51
- id: number;
52
- }
53
-
54
- export class AbstractTranslationEntity<
55
- DTO extends AbstractTranslationDto = AbstractTranslationDto,
56
- O = never,
57
- > extends AbstractEntity<DTO, O> {
58
- @Column({ type: 'enum', enum: LanguageCode })
59
- languageCode: LanguageCode;
60
- }
61
-
62
- export class AbstractStringPrimaryEntity<
63
- DTO extends AbstractDto = AbstractDto,
64
- O = never,
65
- > extends AbstractBaseEntity<DTO, O> {
66
- @PrimaryGeneratedColumn('uuid')
67
- @StringFieldOptional({
68
- maxLength: 36,
69
- minLength: 2,
70
- example: '23247899-c237-4ab1-9639-3322029d2e1c',
71
- })
72
- id: string;
73
- }