@elsikora/nestjs-crud-automator 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/dist/class/api/base-service.class.d.ts +8 -0
  2. package/dist/class/api/base-service.class.js +13 -0
  3. package/dist/class/api/base-service.class.js.map +1 -0
  4. package/dist/class/api/index.d.ts +1 -0
  5. package/dist/class/api/index.js +18 -0
  6. package/dist/class/api/index.js.map +1 -0
  7. package/dist/class/index.d.ts +1 -0
  8. package/dist/class/index.js +18 -0
  9. package/dist/class/index.js.map +1 -0
  10. package/dist/constant/date.constant.d.ts +4 -0
  11. package/dist/constant/date.constant.js +10 -0
  12. package/dist/constant/date.constant.js.map +1 -0
  13. package/dist/constant/decorator/api/function.constant.d.ts +4 -0
  14. package/dist/constant/decorator/api/function.constant.js +9 -0
  15. package/dist/constant/decorator/api/function.constant.js.map +1 -0
  16. package/dist/constant/decorator/api/index.d.ts +1 -0
  17. package/dist/constant/decorator/api/index.js +18 -0
  18. package/dist/constant/decorator/api/index.js.map +1 -0
  19. package/dist/constant/decorator/index.d.ts +1 -0
  20. package/dist/constant/decorator/index.js +18 -0
  21. package/dist/constant/decorator/index.js.map +1 -0
  22. package/dist/constant/dto/exception.constant.d.ts +6 -0
  23. package/dist/constant/dto/exception.constant.js +14 -0
  24. package/dist/constant/dto/exception.constant.js.map +1 -0
  25. package/dist/constant/dto/index.d.ts +1 -0
  26. package/dist/constant/dto/index.js +18 -0
  27. package/dist/constant/dto/index.js.map +1 -0
  28. package/dist/constant/index.d.ts +5 -0
  29. package/dist/constant/index.js +22 -0
  30. package/dist/constant/index.js.map +1 -0
  31. package/dist/constant/interface/api/filter.constant.d.ts +3 -0
  32. package/dist/constant/interface/api/filter.constant.js +12 -0
  33. package/dist/constant/interface/api/filter.constant.js.map +1 -0
  34. package/dist/constant/interface/api/index.d.ts +1 -0
  35. package/dist/constant/interface/api/index.js +18 -0
  36. package/dist/constant/interface/api/index.js.map +1 -0
  37. package/dist/constant/interface/api/property/index.d.ts +2 -0
  38. package/dist/constant/interface/api/property/index.js +19 -0
  39. package/dist/constant/interface/api/property/index.js.map +1 -0
  40. package/dist/constant/interface/api/property/string.constant.d.ts +6 -0
  41. package/dist/constant/interface/api/property/string.constant.js +12 -0
  42. package/dist/constant/interface/api/property/string.constant.js.map +1 -0
  43. package/dist/constant/interface/api/property/wallet.constant.d.ts +5 -0
  44. package/dist/constant/interface/api/property/wallet.constant.js +12 -0
  45. package/dist/constant/interface/api/property/wallet.constant.js.map +1 -0
  46. package/dist/constant/interface/index.d.ts +1 -0
  47. package/dist/constant/interface/index.js +18 -0
  48. package/dist/constant/interface/index.js.map +1 -0
  49. package/dist/constant/number.constant.d.ts +18 -0
  50. package/dist/constant/number.constant.js +38 -0
  51. package/dist/constant/number.constant.js.map +1 -0
  52. package/dist/decorator/api/function/decorator.d.ts +7 -0
  53. package/dist/decorator/api/function/decorator.js +27 -0
  54. package/dist/decorator/api/function/decorator.js.map +1 -0
  55. package/dist/decorator/api/function/get-list.decorator.d.ts +5 -0
  56. package/dist/decorator/api/function/get-list.decorator.js +129 -0
  57. package/dist/decorator/api/function/get-list.decorator.js.map +1 -0
  58. package/dist/decorator/api/function/get.decorator.d.ts +4 -0
  59. package/dist/decorator/api/function/get.decorator.js +58 -0
  60. package/dist/decorator/api/function/get.decorator.js.map +1 -0
  61. package/dist/decorator/api/function/index.d.ts +2 -0
  62. package/dist/decorator/api/function/index.js +19 -0
  63. package/dist/decorator/api/function/index.js.map +1 -0
  64. package/dist/decorator/api/index.d.ts +3 -0
  65. package/dist/decorator/api/index.js +20 -0
  66. package/dist/decorator/api/index.js.map +1 -0
  67. package/dist/decorator/api/method.decorator.d.ts +2 -0
  68. package/dist/decorator/api/method.decorator.js +203 -0
  69. package/dist/decorator/api/method.decorator.js.map +1 -0
  70. package/dist/decorator/api/property/boolean.decorator.d.ts +2 -0
  71. package/dist/decorator/api/property/boolean.decorator.js +77 -0
  72. package/dist/decorator/api/property/boolean.decorator.js.map +1 -0
  73. package/dist/decorator/api/property/date.decorator.d.ts +2 -0
  74. package/dist/decorator/api/property/date.decorator.js +87 -0
  75. package/dist/decorator/api/property/date.decorator.js.map +1 -0
  76. package/dist/decorator/api/property/index.d.ts +7 -0
  77. package/dist/decorator/api/property/index.js +24 -0
  78. package/dist/decorator/api/property/index.js.map +1 -0
  79. package/dist/decorator/api/property/number.decorator.d.ts +2 -0
  80. package/dist/decorator/api/property/number.decorator.js +146 -0
  81. package/dist/decorator/api/property/number.decorator.js.map +1 -0
  82. package/dist/decorator/api/property/object.decorator.d.ts +2 -0
  83. package/dist/decorator/api/property/object.decorator.js +124 -0
  84. package/dist/decorator/api/property/object.decorator.js.map +1 -0
  85. package/dist/decorator/api/property/string.decorator.d.ts +2 -0
  86. package/dist/decorator/api/property/string.decorator.js +282 -0
  87. package/dist/decorator/api/property/string.decorator.js.map +1 -0
  88. package/dist/decorator/api/property/uuid.decorator.d.ts +2 -0
  89. package/dist/decorator/api/property/uuid.decorator.js +63 -0
  90. package/dist/decorator/api/property/uuid.decorator.js.map +1 -0
  91. package/dist/decorator/api/property/wallet.decorator.d.ts +2 -0
  92. package/dist/decorator/api/property/wallet.decorator.js +25 -0
  93. package/dist/decorator/api/property/wallet.decorator.js.map +1 -0
  94. package/dist/decorator/api/service.decorator.d.ts +8 -0
  95. package/dist/decorator/api/service.decorator.js +71 -0
  96. package/dist/decorator/api/service.decorator.js.map +1 -0
  97. package/dist/decorator/index.d.ts +1 -0
  98. package/dist/decorator/index.js +18 -0
  99. package/dist/decorator/index.js.map +1 -0
  100. package/dist/dto/exception/bad-request.dto.d.ts +8 -0
  101. package/dist/dto/exception/bad-request.dto.js +84 -0
  102. package/dist/dto/exception/bad-request.dto.js.map +1 -0
  103. package/dist/dto/exception/conflict.dto.d.ts +8 -0
  104. package/dist/dto/exception/conflict.dto.js +84 -0
  105. package/dist/dto/exception/conflict.dto.js.map +1 -0
  106. package/dist/dto/exception/forbidden.dto.d.ts +8 -0
  107. package/dist/dto/exception/forbidden.dto.js +84 -0
  108. package/dist/dto/exception/forbidden.dto.js.map +1 -0
  109. package/dist/dto/exception/index.d.ts +7 -0
  110. package/dist/dto/exception/index.js +24 -0
  111. package/dist/dto/exception/index.js.map +1 -0
  112. package/dist/dto/exception/internal-server-error.dto.d.ts +8 -0
  113. package/dist/dto/exception/internal-server-error.dto.js +84 -0
  114. package/dist/dto/exception/internal-server-error.dto.js.map +1 -0
  115. package/dist/dto/exception/not-found.dto.d.ts +8 -0
  116. package/dist/dto/exception/not-found.dto.js +84 -0
  117. package/dist/dto/exception/not-found.dto.js.map +1 -0
  118. package/dist/dto/exception/too-many-requests.dto.d.ts +8 -0
  119. package/dist/dto/exception/too-many-requests.dto.js +84 -0
  120. package/dist/dto/exception/too-many-requests.dto.js.map +1 -0
  121. package/dist/dto/exception/unauthorized.dto.d.ts +8 -0
  122. package/dist/dto/exception/unauthorized.dto.js +84 -0
  123. package/dist/dto/exception/unauthorized.dto.js.map +1 -0
  124. package/dist/dto/index.d.ts +1 -0
  125. package/dist/dto/index.js +18 -0
  126. package/dist/dto/index.js.map +1 -0
  127. package/dist/enum/decorator/api/action.enum.d.ts +14 -0
  128. package/dist/enum/decorator/api/action.enum.js +19 -0
  129. package/dist/enum/decorator/api/action.enum.js.map +1 -0
  130. package/dist/enum/decorator/api/authentication-type.enum.d.ts +5 -0
  131. package/dist/enum/decorator/api/authentication-type.enum.js +10 -0
  132. package/dist/enum/decorator/api/authentication-type.enum.js.map +1 -0
  133. package/dist/enum/decorator/api/function/index.d.ts +1 -0
  134. package/dist/enum/decorator/api/function/index.js +18 -0
  135. package/dist/enum/decorator/api/function/index.js.map +1 -0
  136. package/dist/enum/decorator/api/function/type.enum.d.ts +10 -0
  137. package/dist/enum/decorator/api/function/type.enum.js +15 -0
  138. package/dist/enum/decorator/api/function/type.enum.js.map +1 -0
  139. package/dist/enum/decorator/api/index.d.ts +4 -0
  140. package/dist/enum/decorator/api/index.js +21 -0
  141. package/dist/enum/decorator/api/index.js.map +1 -0
  142. package/dist/enum/decorator/api/property/data-type.enum.d.ts +23 -0
  143. package/dist/enum/decorator/api/property/data-type.enum.js +42 -0
  144. package/dist/enum/decorator/api/property/data-type.enum.js.map +1 -0
  145. package/dist/enum/decorator/api/property/date-type.enum.d.ts +14 -0
  146. package/dist/enum/decorator/api/property/date-type.enum.js +19 -0
  147. package/dist/enum/decorator/api/property/date-type.enum.js.map +1 -0
  148. package/dist/enum/decorator/api/property/index.d.ts +2 -0
  149. package/dist/enum/decorator/api/property/index.js +19 -0
  150. package/dist/enum/decorator/api/property/index.js.map +1 -0
  151. package/dist/enum/decorator/index.d.ts +1 -0
  152. package/dist/enum/decorator/index.js +18 -0
  153. package/dist/enum/decorator/index.js.map +1 -0
  154. package/dist/enum/filter-order-direction.enum.d.ts +4 -0
  155. package/dist/enum/filter-order-direction.enum.js +9 -0
  156. package/dist/enum/filter-order-direction.enum.js.map +1 -0
  157. package/dist/enum/index.d.ts +3 -0
  158. package/dist/enum/index.js +20 -0
  159. package/dist/enum/index.js.map +1 -0
  160. package/dist/enum/utility/error-string-action.enum.d.ts +55 -0
  161. package/dist/enum/utility/error-string-action.enum.js +60 -0
  162. package/dist/enum/utility/error-string-action.enum.js.map +1 -0
  163. package/dist/enum/utility/index.d.ts +1 -0
  164. package/dist/enum/utility/index.js +18 -0
  165. package/dist/enum/utility/index.js.map +1 -0
  166. package/dist/index.d.ts +10 -0
  167. package/dist/index.js +27 -0
  168. package/dist/index.js.map +1 -0
  169. package/dist/interceptor/correlation-id-response-body.interceptor.d.ts +5 -0
  170. package/dist/interceptor/correlation-id-response-body.interceptor.js +90 -0
  171. package/dist/interceptor/correlation-id-response-body.interceptor.js.map +1 -0
  172. package/dist/interceptor/index.d.ts +1 -0
  173. package/dist/interceptor/index.js +18 -0
  174. package/dist/interceptor/index.js.map +1 -0
  175. package/dist/interface/api-base-entity.interface.d.ts +3 -0
  176. package/dist/interface/api-base-entity.interface.js +3 -0
  177. package/dist/interface/api-base-entity.interface.js.map +1 -0
  178. package/dist/interface/decorator/api/function/index.d.ts +1 -0
  179. package/dist/interface/decorator/api/function/index.js +3 -0
  180. package/dist/interface/decorator/api/function/index.js.map +1 -0
  181. package/dist/interface/decorator/api/get-list-response-result.interface.d.ts +7 -0
  182. package/dist/interface/decorator/api/get-list-response-result.interface.js +3 -0
  183. package/dist/interface/decorator/api/get-list-response-result.interface.js.map +1 -0
  184. package/dist/interface/decorator/api/index.d.ts +5 -0
  185. package/dist/interface/decorator/api/index.js +22 -0
  186. package/dist/interface/decorator/api/index.js.map +1 -0
  187. package/dist/interface/decorator/api/method/index.d.ts +2 -0
  188. package/dist/interface/decorator/api/method/index.js +19 -0
  189. package/dist/interface/decorator/api/method/index.js.map +1 -0
  190. package/dist/interface/decorator/api/method/properties.interface.d.ts +16 -0
  191. package/dist/interface/decorator/api/method/properties.interface.js +3 -0
  192. package/dist/interface/decorator/api/method/properties.interface.js.map +1 -0
  193. package/dist/interface/decorator/api/method/throttler-properties.interface.d.ts +4 -0
  194. package/dist/interface/decorator/api/method/throttler-properties.interface.js +3 -0
  195. package/dist/interface/decorator/api/method/throttler-properties.interface.js.map +1 -0
  196. package/dist/interface/decorator/api/property/base-properties.interface.d.ts +13 -0
  197. package/dist/interface/decorator/api/property/base-properties.interface.js +3 -0
  198. package/dist/interface/decorator/api/property/base-properties.interface.js.map +1 -0
  199. package/dist/interface/decorator/api/property/date-properties.interface.d.ts +5 -0
  200. package/dist/interface/decorator/api/property/date-properties.interface.js +3 -0
  201. package/dist/interface/decorator/api/property/date-properties.interface.js.map +1 -0
  202. package/dist/interface/decorator/api/property/index.d.ts +6 -0
  203. package/dist/interface/decorator/api/property/index.js +23 -0
  204. package/dist/interface/decorator/api/property/index.js.map +1 -0
  205. package/dist/interface/decorator/api/property/number-properties.interface.d.ts +9 -0
  206. package/dist/interface/decorator/api/property/number-properties.interface.js +3 -0
  207. package/dist/interface/decorator/api/property/number-properties.interface.js.map +1 -0
  208. package/dist/interface/decorator/api/property/object-properties.interface.d.ts +10 -0
  209. package/dist/interface/decorator/api/property/object-properties.interface.js +3 -0
  210. package/dist/interface/decorator/api/property/object-properties.interface.js.map +1 -0
  211. package/dist/interface/decorator/api/property/string-properties.interface.d.ts +10 -0
  212. package/dist/interface/decorator/api/property/string-properties.interface.js +3 -0
  213. package/dist/interface/decorator/api/property/string-properties.interface.js.map +1 -0
  214. package/dist/interface/decorator/api/property/uuid-properties.interface.d.ts +8 -0
  215. package/dist/interface/decorator/api/property/uuid-properties.interface.js +3 -0
  216. package/dist/interface/decorator/api/property/uuid-properties.interface.js.map +1 -0
  217. package/dist/interface/decorator/api/response-type.interface.d.ts +9 -0
  218. package/dist/interface/decorator/api/response-type.interface.js +3 -0
  219. package/dist/interface/decorator/api/response-type.interface.js.map +1 -0
  220. package/dist/interface/decorator/index.d.ts +1 -0
  221. package/dist/interface/decorator/index.js +18 -0
  222. package/dist/interface/decorator/index.js.map +1 -0
  223. package/dist/interface/index.d.ts +4 -0
  224. package/dist/interface/index.js +21 -0
  225. package/dist/interface/index.js.map +1 -0
  226. package/dist/interface/service.interface.d.ts +1 -0
  227. package/dist/interface/service.interface.js +3 -0
  228. package/dist/interface/service.interface.js.map +1 -0
  229. package/dist/interface/utility/error-string-properties.interface.d.ts +5 -0
  230. package/dist/interface/utility/error-string-properties.interface.js +3 -0
  231. package/dist/interface/utility/error-string-properties.interface.js.map +1 -0
  232. package/dist/interface/utility/index.d.ts +1 -0
  233. package/dist/interface/utility/index.js +18 -0
  234. package/dist/interface/utility/index.js.map +1 -0
  235. package/dist/tsconfig.build.tsbuildinfo +1 -0
  236. package/dist/type/api/filter/allowed-types.type.d.ts +1 -0
  237. package/dist/type/api/filter/allowed-types.type.js +3 -0
  238. package/dist/type/api/filter/allowed-types.type.js.map +1 -0
  239. package/dist/type/api/filter/extracted-allowed-types.type.d.ts +2 -0
  240. package/dist/type/api/filter/extracted-allowed-types.type.js +3 -0
  241. package/dist/type/api/filter/extracted-allowed-types.type.js.map +1 -0
  242. package/dist/type/api/filter/field-selector.type.d.ts +3 -0
  243. package/dist/type/api/filter/field-selector.type.js +3 -0
  244. package/dist/type/api/filter/field-selector.type.js.map +1 -0
  245. package/dist/type/api/filter/index.d.ts +4 -0
  246. package/dist/type/api/filter/index.js +21 -0
  247. package/dist/type/api/filter/index.js.map +1 -0
  248. package/dist/type/api/filter/order-by.type.d.ts +5 -0
  249. package/dist/type/api/filter/order-by.type.js +3 -0
  250. package/dist/type/api/filter/order-by.type.js.map +1 -0
  251. package/dist/type/api/function/get-list-properties.type.d.ts +23 -0
  252. package/dist/type/api/function/get-list-properties.type.js +3 -0
  253. package/dist/type/api/function/get-list-properties.type.js.map +1 -0
  254. package/dist/type/api/function/get-properties.type.d.ts +6 -0
  255. package/dist/type/api/function/get-properties.type.js +3 -0
  256. package/dist/type/api/function/get-properties.type.js.map +1 -0
  257. package/dist/type/api/function/index.d.ts +1 -0
  258. package/dist/type/api/function/index.js +18 -0
  259. package/dist/type/api/function/index.js.map +1 -0
  260. package/dist/type/api/index.d.ts +2 -0
  261. package/dist/type/api/index.js +19 -0
  262. package/dist/type/api/index.js.map +1 -0
  263. package/dist/type/index.d.ts +1 -0
  264. package/dist/type/index.js +18 -0
  265. package/dist/type/index.js.map +1 -0
  266. package/dist/utility/api/filter-order-by-from-entity.utility.d.ts +4 -0
  267. package/dist/utility/api/filter-order-by-from-entity.utility.js +34 -0
  268. package/dist/utility/api/filter-order-by-from-entity.utility.js.map +1 -0
  269. package/dist/utility/api/index.d.ts +1 -0
  270. package/dist/utility/api/index.js +18 -0
  271. package/dist/utility/api/index.js.map +1 -0
  272. package/dist/utility/create-rest-application.utility.d.ts +3 -0
  273. package/dist/utility/create-rest-application.utility.js +9 -0
  274. package/dist/utility/create-rest-application.utility.js.map +1 -0
  275. package/dist/utility/error-string.utility.d.ts +2 -0
  276. package/dist/utility/error-string.utility.js +7 -0
  277. package/dist/utility/error-string.utility.js.map +1 -0
  278. package/dist/utility/index.d.ts +3 -0
  279. package/dist/utility/index.js +20 -0
  280. package/dist/utility/index.js.map +1 -0
  281. package/dist/validator/index.d.ts +1 -0
  282. package/dist/validator/index.js +18 -0
  283. package/dist/validator/index.js.map +1 -0
  284. package/dist/validator/is-regular-expression.validator.d.ts +4 -0
  285. package/dist/validator/is-regular-expression.validator.js +31 -0
  286. package/dist/validator/is-regular-expression.validator.js.map +1 -0
  287. package/package.json +64 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiFunctionGetList = ApiFunctionGetList;
4
+ const typeorm_1 = require("typeorm");
5
+ const common_1 = require("@nestjs/common");
6
+ const utility_1 = require("../../../utility");
7
+ const enum_1 = require("../../../enum");
8
+ const constant_1 = require("../../../constant");
9
+ async function executor(repository, entityType, properties, filter) {
10
+ try {
11
+ const [items, totalCount] = await repository.findAndCount(filter);
12
+ if (items.length === 0) {
13
+ throw new common_1.NotFoundException((0, utility_1.ErrorString)({
14
+ entity: entityType,
15
+ type: enum_1.EErrorStringAction.LIST_PAGE_NOT_FOUND,
16
+ }));
17
+ }
18
+ return {
19
+ count: items.length,
20
+ currentPage: properties.page,
21
+ items,
22
+ totalCount,
23
+ totalPages: Math.ceil(totalCount / properties.limit),
24
+ };
25
+ }
26
+ catch (error) {
27
+ if (error instanceof common_1.HttpException) {
28
+ throw error;
29
+ }
30
+ throw new common_1.InternalServerErrorException((0, utility_1.ErrorString)({
31
+ entity: entityType,
32
+ type: enum_1.EErrorStringAction.FETCHING_LIST_ERROR,
33
+ }));
34
+ }
35
+ }
36
+ function ApiFunctionGetList(options) {
37
+ return function (_target, _propertyKey, descriptor) {
38
+ descriptor.value = async function (properties) {
39
+ const { limit, orderBy, orderDirection, page, createdAtFrom, createdAtTo, updatedAtFrom, updatedAtTo, receivedAtFrom, receivedAtTo, ...entityProperties } = properties;
40
+ const filter = {
41
+ skip: limit * (page - 1),
42
+ take: limit,
43
+ where: {},
44
+ relations: options.relations,
45
+ };
46
+ const typedEntityProperties = entityProperties;
47
+ Object.keys(typedEntityProperties).forEach((key) => {
48
+ if (typeof typedEntityProperties[key] === "string") {
49
+ filter.where = {
50
+ ...filter.where,
51
+ [key]: (0, typeorm_1.Like)(`%${typedEntityProperties[key]}%`),
52
+ };
53
+ }
54
+ });
55
+ if (orderBy) {
56
+ filter.order = {
57
+ [orderBy]: orderDirection || constant_1.API_FUNCTION_DECORATOR_CONSTANT.DEFAULT_FILTER_ORDER_BY_DIRECTION,
58
+ };
59
+ }
60
+ if ("createdAt" in options.model.prototype) {
61
+ if (createdAtFrom && createdAtTo) {
62
+ filter.where = {
63
+ ...filter.where,
64
+ createdAt: (0, typeorm_1.Between)(createdAtFrom, createdAtTo),
65
+ };
66
+ }
67
+ else if (createdAtFrom) {
68
+ filter.where = {
69
+ ...filter.where,
70
+ createdAt: (0, typeorm_1.MoreThanOrEqual)(createdAtFrom),
71
+ };
72
+ }
73
+ else if (createdAtTo) {
74
+ filter.where = {
75
+ ...filter.where,
76
+ createdAt: (0, typeorm_1.LessThanOrEqual)(createdAtTo),
77
+ };
78
+ }
79
+ }
80
+ if ("updatedAt" in options.model.prototype) {
81
+ if (updatedAtFrom && updatedAtTo) {
82
+ filter.where = {
83
+ ...filter.where,
84
+ updatedAt: (0, typeorm_1.Between)(updatedAtFrom, updatedAtTo),
85
+ };
86
+ }
87
+ else if (updatedAtFrom) {
88
+ filter.where = {
89
+ ...filter.where,
90
+ updatedAt: (0, typeorm_1.MoreThanOrEqual)(updatedAtFrom),
91
+ };
92
+ }
93
+ else if (updatedAtTo) {
94
+ filter.where = {
95
+ ...filter.where,
96
+ updatedAt: (0, typeorm_1.LessThanOrEqual)(updatedAtTo),
97
+ };
98
+ }
99
+ }
100
+ if ("receivedAt" in options.model.prototype) {
101
+ if (receivedAtFrom && receivedAtTo) {
102
+ filter.where = {
103
+ ...filter.where,
104
+ receivedAt: (0, typeorm_1.Between)(receivedAtFrom, receivedAtTo),
105
+ };
106
+ }
107
+ else if (receivedAtFrom) {
108
+ filter.where = {
109
+ ...filter.where,
110
+ receivedAt: (0, typeorm_1.MoreThanOrEqual)(receivedAtFrom),
111
+ };
112
+ }
113
+ else if (receivedAtTo) {
114
+ filter.where = {
115
+ ...filter.where,
116
+ receivedAt: (0, typeorm_1.LessThanOrEqual)(receivedAtTo),
117
+ };
118
+ }
119
+ }
120
+ const repository = this.repository;
121
+ if (!repository) {
122
+ throw new Error("Repository is not available in this context");
123
+ }
124
+ return executor(repository, options.model, properties, filter);
125
+ };
126
+ return descriptor;
127
+ };
128
+ }
129
+ //# sourceMappingURL=get-list.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-list.decorator.js","sourceRoot":"/","sources":["decorator/api/function/get-list.decorator.ts"],"names":[],"mappings":";;AA0CA,gDAqGC;AA9ID,qCAA0E;AAE1E,2CAAgG;AAEhG,8CAA+C;AAC/C,wCAAmD;AACnD,gDAAoE;AAGpE,KAAK,UAAU,QAAQ,CAAuB,UAAyB,EAAE,UAAuB,EAAE,UAA4C,EAAE,MAA0B;IACzK,IAAI,CAAC;QACJ,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAElE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,0BAAiB,CAC1B,IAAA,qBAAW,EAAC;gBACX,MAAM,EAAE,UAAU;gBAClB,IAAI,EAAE,yBAAkB,CAAC,mBAAmB;aAC5C,CAAC,CACF,CAAC;QACH,CAAC;QAED,OAAO;YACN,KAAK,EAAE,KAAK,CAAC,MAAM;YACnB,WAAW,EAAE,UAAU,CAAC,IAAI;YAC5B,KAAK;YACL,UAAU;YACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;SACpD,CAAC;IACH,CAAC;IAAC,OAAO,K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AAe,EAAC,WAAW,CAAC;qBACvC,CAAC;gBACH,CAAC;YACF,CAAC;YAED,IAAI,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC7C,IAAI,cAAc,IAAI,YAAY,EAAE,CAAC;oBACpC,MAAM,CAAC,KAAK,GAAG;wBACd,GAAG,MAAM,CAAC,KAAK;wBACf,UAAU,EAAE,IAAA,iBAAO,EAAC,cAAc,EAAE,YAAY,CAAC;qBACjD,CAAC;gBACH,CAAC;qBAAM,IAAI,cAAc,EAAE,CAAC;oBAC3B,MAAM,CAAC,KAAK,GAAG;wBACd,GAAG,MAAM,CAAC,KAAK;wBACf,UAAU,EAAE,IAAA,yBAAe,EAAC,cAAc,CAAC;qBAC3C,CAAC;gBACH,CAAC;qBAAM,IAAI,YAAY,EAAE,CAAC;oBACzB,MAAM,CAAC,KAAK,GAAG;wBACd,GAAG,MAAM,CAAC,KAAK;wBACf,UAAU,EAAE,IAAA,yBAAe,EAAC,YAAY,CAAC;qBACzC,CAAC;gBACH,CAAC;YACF,CAAC;YAED,MAAM,UAAU,GAAkB,IAAI,CAAC,UAAU,CAAC;YAClD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAChE,CAAC;YAED,OAAO,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QAChE,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACnB,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type {BaseEntity, FindManyOptions, FindOptionsRelations, Repository} from \"typeorm\";\nimport { Between, LessThanOrEqual, Like, MoreThanOrEqual } from \"typeorm\";\n\nimport { HttpException, InternalServerErrorException, NotFoundException } from \"@nestjs/common\";\nimport type { IApiGetListResponseResult } from \"../../../interface\";\nimport { ErrorString } from \"../../../utility\";\nimport { EErrorStringAction } from \"../../../enum\";\nimport { API_FUNCTION_DECORATOR_CONSTANT } from \"../../../constant\";\nimport { TApiFunctionGetListProperties } from \"../../../type\";\n\nasync function executor<E extends BaseEntity>(repository: Repository<E>, entityType: new () => E, properties: TApiFunctionGetListProperties<E>, filter: FindManyOptions<E>): Promise<IApiGetListResponseResult<E>> {\n\ttry {\n\t\tconst [items, totalCount] = await repository.findAndCount(filter);\n\n\t\tif (items.length === 0) {\n\t\t\tthrow new NotFoundException(\n\t\t\t\tErrorString({\n\t\t\t\t\tentity: entityType,\n\t\t\t\t\ttype: EErrorStringAction.LIST_PAGE_NOT_FOUND,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tcount: items.length,\n\t\t\tcurrentPage: properties.page,\n\t\t\titems,\n\t\t\ttotalCount,\n\t\t\ttotalPages: Math.ceil(totalCount / properties.limit),\n\t\t};\n\t} catch (error) {\n\t\tif (error instanceof HttpException) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new InternalServerErrorException(\n\t\t\tErrorString({\n\t\t\t\tentity: entityType,\n\t\t\t\ttype: EErrorStringAction.FETCHING_LIST_ERROR,\n\t\t\t}),\n\t\t);\n\t}\n}\nexport function ApiFunctionGetList<E extends BaseEntity>(options: { model: new () => E; relations?: FindOptionsRelations<E> }) {\n\treturn function (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) {\n\t\tdescriptor.value = async function (\n\t\t\tthis: {\n\t\t\t\trepository: Repository<E>;\n\t\t\t},\n\t\t\tproperties: TApiFunctionGetListProperties<InstanceType<typeof options.model>>,\n\t\t) {\n\t\t\tconst { limit, orderBy, orderDirection, page, createdAtFrom, createdAtTo, updatedAtFrom, updatedAtTo, receivedAtFrom, receivedAtTo, ...entityProperties } = properties;\n\n\t\t\tconst filter: FindManyOptions<typeof options.model> = {\n\t\t\t\tskip: limit * (page - 1),\n\t\t\t\ttake: limit,\n\t\t\t\twhere: {},\n\t\t\t\trelations: options.relations,\n\t\t\t};\n\n\t\t\tconst typedEntityProperties: keyof typeof options.model = entityProperties as Exclude<keyof Omit<E, \"createdAt\" | \"updatedAt\" | \"receivedAt\">, keyof E>;\n\n\t\t\tObject.keys(typedEntityProperties).forEach((key: string) => {\n\t\t\t\tif (typeof typedEntityProperties[key] === \"string\") {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\t[key]: Like(`%${typedEntityProperties[key]}%`),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (orderBy) {\n\t\t\t\tfilter.order = {\n\t\t\t\t\t[orderBy as never as string]: orderDirection || API_FUNCTION_DECORATOR_CONSTANT.DEFAULT_FILTER_ORDER_BY_DIRECTION,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (\"createdAt\" in options.model.prototype) {\n\t\t\t\tif (createdAtFrom && createdAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tcreatedAt: Between(createdAtFrom, createdAtTo),\n\t\t\t\t\t};\n\t\t\t\t} else if (createdAtFrom) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tcreatedAt: MoreThanOrEqual(createdAtFrom),\n\t\t\t\t\t};\n\t\t\t\t} else if (createdAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tcreatedAt: LessThanOrEqual(createdAtTo),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"updatedAt\" in options.model.prototype) {\n\t\t\t\tif (updatedAtFrom && updatedAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tupdatedAt: Between(updatedAtFrom, updatedAtTo),\n\t\t\t\t\t};\n\t\t\t\t} else if (updatedAtFrom) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tupdatedAt: MoreThanOrEqual(updatedAtFrom),\n\t\t\t\t\t};\n\t\t\t\t} else if (updatedAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\tupdatedAt: LessThanOrEqual(updatedAtTo),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"receivedAt\" in options.model.prototype) {\n\t\t\t\tif (receivedAtFrom && receivedAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\treceivedAt: Between(receivedAtFrom, receivedAtTo),\n\t\t\t\t\t};\n\t\t\t\t} else if (receivedAtFrom) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\treceivedAt: MoreThanOrEqual(receivedAtFrom),\n\t\t\t\t\t};\n\t\t\t\t} else if (receivedAtTo) {\n\t\t\t\t\tfilter.where = {\n\t\t\t\t\t\t...filter.where,\n\t\t\t\t\t\treceivedAt: LessThanOrEqual(receivedAtTo),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst repository: Repository<E> = this.repository;\n\t\t\tif (!repository) {\n\t\t\t\tthrow new Error(\"Repository is not available in this context\");\n\t\t\t}\n\n\t\t\treturn executor(repository, options.model, properties, filter);\n\t\t};\n\n\t\treturn descriptor;\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { BaseEntity } from "typeorm";
2
+ export declare function ApiFunctionGet<E extends BaseEntity>(options: {
3
+ model: new () => E;
4
+ }): (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiFunctionGet = ApiFunctionGet;
4
+ const typeorm_1 = require("typeorm");
5
+ const common_1 = require("@nestjs/common");
6
+ const utility_1 = require("../../../utility");
7
+ const enum_1 = require("../../../enum");
8
+ async function executor(repository, model, filter) {
9
+ try {
10
+ console.log("FILTER", filter);
11
+ const item = await repository.findOne(filter);
12
+ if (!item) {
13
+ throw new common_1.NotFoundException((0, utility_1.ErrorString)({ entity: model, type: enum_1.EErrorStringAction.NOT_FOUND }));
14
+ }
15
+ return item;
16
+ }
17
+ catch (error) {
18
+ console.log("PISKO", error, error instanceof common_1.HttpException);
19
+ if (error instanceof common_1.HttpException) {
20
+ throw error;
21
+ }
22
+ console.log("A TYT CHE ZABYL");
23
+ throw new common_1.InternalServerErrorException((0, utility_1.ErrorString)({
24
+ entity: model,
25
+ type: enum_1.EErrorStringAction.FETCHING_ERROR,
26
+ }));
27
+ }
28
+ }
29
+ function ApiFunctionGet(options) {
30
+ return function (_target, _propertyKey, descriptor) {
31
+ descriptor.value = async function (id, properties, relations) {
32
+ const filter = {
33
+ where: { id },
34
+ relations: relations,
35
+ };
36
+ if (properties) {
37
+ const { ...entityProperties } = properties;
38
+ const typedEntityProperties = entityProperties;
39
+ Object.keys(typedEntityProperties).forEach((key) => {
40
+ if (typeof typedEntityProperties[key] === "string") {
41
+ filter.where = {
42
+ ...filter.where,
43
+ [key]: (0, typeorm_1.Like)(`%${typedEntityProperties[key]}%`),
44
+ };
45
+ }
46
+ });
47
+ }
48
+ const repository = this.repository;
49
+ if (!repository) {
50
+ throw new Error("Repository is not available in this context");
51
+ }
52
+ return executor(repository, options.model, filter);
53
+ };
54
+ console.log("DESC", descriptor);
55
+ return descriptor;
56
+ };
57
+ }
58
+ //# sourceMappingURL=get.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.decorator.js","sourceRoot":"/","sources":["decorator/api/function/get.decorator.ts"],"names":[],"mappings":";;AAiCA,wCA0CC;AA1ED,qCAA+B;AAE/B,2CAAgG;AAChG,8CAA+C;AAC/C,wCAAmD;AAGnD,KAAK,UAAU,QAAQ,CAAuB,UAAyB,EAAE,KAAkB,EAAE,MAAyB;IAClH,IAAI,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC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AK,QAAQ,EAAE,CAAC;wBACjD,MAAM,CAAC,KAAK,GAAG;4BACX,GAAG,MAAM,CAAC,KAAK;4BACf,CAAC,GAAG,CAAC,EAAE,IAAA,cAAI,EAAC,IAAI,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC;yBACjD,CAAC;oBACN,CAAC;gBACL,CAAC,CAAC,CAAC;YACH,CAAC;YAED,MAAM,UAAU,GAAkB,IAAI,CAAC,UAAU,CAAC;YAClD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACnE,CAAC;YAED,OAAO,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvD,CAAC,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import type {BaseEntity, FindManyOptions, FindOneOptions, FindOptionsRelations, Repository} from \"typeorm\";\nimport { Like } from \"typeorm\";\n\nimport { HttpException, InternalServerErrorException, NotFoundException } from \"@nestjs/common\";\nimport { ErrorString } from \"../../../utility\";\nimport { EErrorStringAction } from \"../../../enum\";\nimport {TApiFunctionGetProperties} from \"../../../type/api/function/get-properties.type\";\n\nasync function executor<E extends BaseEntity>(repository: Repository<E>, model: new () => E, filter: FindOneOptions<E>): Promise<E> {\n try {\n console.log(\"FILTER\", filter);\n const item: E | null = await repository.findOne(filter);\n\n if (!item) {\n throw new NotFoundException(ErrorString({ entity: model, type: EErrorStringAction.NOT_FOUND }));\n }\n\n return item;\n } catch (error) {\n console.log(\"PISKO\", error, error instanceof HttpException);\n if (error instanceof HttpException) {\n throw error;\n }\n\n console.log(\"A TYT CHE ZABYL\");\n throw new InternalServerErrorException(\n ErrorString({\n entity: model,\n type: EErrorStringAction.FETCHING_ERROR,\n }),\n );\n }\n}\nexport function ApiFunctionGet<E extends BaseEntity>(options: { model: new () => E; }) {\n return function (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) {\n descriptor.value = async function (\n this: {\n repository: Repository<E>;\n },\n id: string,\n properties?: TApiFunctionGetProperties<InstanceType<typeof options.model>>,\n relations?: FindOptionsRelations<E>\n ) {\n\n const filter: FindManyOptions<typeof options.model> = {\n where: { id },\n relations: relations,\n };\n\n if (properties) {\n const {...entityProperties} = properties;\n\n const typedEntityProperties: keyof typeof options.model = entityProperties as Exclude<keyof Omit<E, \"createdAt\" | \"updatedAt\" | \"receivedAt\">, keyof E>;\n\n Object.keys(typedEntityProperties).forEach((key: string) => {\n if (typeof typedEntityProperties[key] === \"string\") {\n filter.where = {\n ...filter.where,\n [key]: Like(`%${typedEntityProperties[key]}%`),\n };\n }\n });\n }\n\n const repository: Repository<E> = this.repository;\n if (!repository) {\n throw new Error(\"Repository is not available in this context\");\n }\n\n return executor(repository, options.model, filter);\n };\n\n console.log(\"DESC\", descriptor);\n return descriptor;\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./decorator";
2
+ export * from "./get-list.decorator";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decorator"), exports);
18
+ __exportStar(require("./get-list.decorator"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["decorator/api/function/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,uDAAqC","sourcesContent":["export * from \"./decorator\";\nexport * from \"./get-list.decorator\";\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./function";
2
+ export * from "./property";
3
+ export * from "./service.decorator";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./function"), exports);
18
+ __exportStar(require("./property"), exports);
19
+ __exportStar(require("./service.decorator"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["decorator/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B;AAC3B,sDAAoC","sourcesContent":["export * from \"./function\";\nexport * from \"./property\";\nexport * from \"./service.decorator\";\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiMethodProperties } from "../../interface";
2
+ export declare function ApiMethod<T extends IApiBaseEntity>(options: IApiMethodProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiMethod = ApiMethod;
4
+ const common_1 = require("@nestjs/common");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ const throttler_1 = require("@nestjs/throttler");
7
+ const enum_1 = require("../../enum");
8
+ const bad_request_dto_1 = require("../../dto/exception/bad-request.dto");
9
+ const forbidden_dto_1 = require("../../dto/exception/forbidden.dto");
10
+ const internal_server_error_dto_1 = require("../../dto/exception/internal-server-error.dto");
11
+ const not_found_dto_1 = require("../../dto/exception/not-found.dto");
12
+ const too_many_requests_dto_1 = require("../../dto/exception/too-many-requests.dto");
13
+ const unauthorized_dto_1 = require("../../dto/exception/unauthorized.dto");
14
+ function ApiMethod(options) {
15
+ let summary = "";
16
+ if (options.action) {
17
+ switch (options.action) {
18
+ case enum_1.EApiAction.FETCH: {
19
+ summary = `Fetching \`${options.entity.name}\``;
20
+ break;
21
+ }
22
+ case enum_1.EApiAction.CREATE: {
23
+ summary = `Creating \`${options.entity.name}\``;
24
+ break;
25
+ }
26
+ case enum_1.EApiAction.UPDATE: {
27
+ summary = `Updating \`${options.entity.name}\``;
28
+ break;
29
+ }
30
+ case enum_1.EApiAction.DELETE: {
31
+ summary = `Deleting \`${options.entity.name}\``;
32
+ break;
33
+ }
34
+ case enum_1.EApiAction.PARTIAL_UPDATE: {
35
+ summary = `Partial updating \`${options.entity.name}\``;
36
+ break;
37
+ }
38
+ case enum_1.EApiAction.FETCH_LIST: {
39
+ summary = `Fetching list of \`${options.entity.name}s\``;
40
+ break;
41
+ }
42
+ case enum_1.EApiAction.FETCH_SPECIFIED: {
43
+ summary = `Fetching \`${options.entity.name}\` of specified item`;
44
+ break;
45
+ }
46
+ case enum_1.EApiAction.REGISTRATION: {
47
+ summary = `Registration of \`${options.entity.name}\``;
48
+ break;
49
+ }
50
+ case enum_1.EApiAction.AUTHENTICATION: {
51
+ summary = `Authentication of \`${options.entity.name}\``;
52
+ break;
53
+ }
54
+ case enum_1.EApiAction.CONFIRMATION: {
55
+ summary = `Confirmation of \`${options.entity.name}\``;
56
+ break;
57
+ }
58
+ case enum_1.EApiAction.REFRESH: {
59
+ summary = `Refresh of \`${options.entity.name}\``;
60
+ break;
61
+ }
62
+ case enum_1.EApiAction.FETCH_SIMPLE_LIST: {
63
+ summary = `Fetching simple list of \`${options.entity.name}s\``;
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ if (!options.description && options.action) {
69
+ switch (options.action) {
70
+ case enum_1.EApiAction.FETCH: {
71
+ options.description = `This method is used for fetching \`${options.entity.name}\``;
72
+ break;
73
+ }
74
+ case enum_1.EApiAction.CREATE: {
75
+ options.description = `This method is used for creating \`${options.entity.name}\``;
76
+ break;
77
+ }
78
+ case enum_1.EApiAction.UPDATE: {
79
+ options.description = `This method is used for updating \`${options.entity.name}\``;
80
+ break;
81
+ }
82
+ case enum_1.EApiAction.DELETE: {
83
+ options.description = `This method is used for deleting \`${options.entity.name}\``;
84
+ break;
85
+ }
86
+ case enum_1.EApiAction.PARTIAL_UPDATE: {
87
+ options.description = `This method is used for partial updating \`${options.entity.name}\``;
88
+ break;
89
+ }
90
+ case enum_1.EApiAction.FETCH_LIST: {
91
+ options.description = `This method is used for fetching list of \`${options.entity.name}s\``;
92
+ break;
93
+ }
94
+ case enum_1.EApiAction.FETCH_SPECIFIED: {
95
+ options.description = `This method is used for fetching \`${options.entity.name}\` of specified item`;
96
+ break;
97
+ }
98
+ case enum_1.EApiAction.REGISTRATION: {
99
+ options.description = `This method is used for registration of \`${options.entity.name}\``;
100
+ break;
101
+ }
102
+ case enum_1.EApiAction.AUTHENTICATION: {
103
+ options.description = `This method is used for authentication of \`${options.entity.name}\``;
104
+ break;
105
+ }
106
+ case enum_1.EApiAction.CONFIRMATION: {
107
+ options.description = `This method is used for confirmation of \`${options.entity.name}\``;
108
+ break;
109
+ }
110
+ case enum_1.EApiAction.REFRESH: {
111
+ options.description = `This method is used for refresh of \`${options.entity.name}\``;
112
+ break;
113
+ }
114
+ case enum_1.EApiAction.FETCH_SIMPLE_LIST: {
115
+ options.description = `This method is used for fetching simple list of \`${options.entity.name}s\``;
116
+ break;
117
+ }
118
+ }
119
+ }
120
+ const decorators = [
121
+ (0, swagger_1.ApiOperation)({ description: options.description, summary }),
122
+ (0, swagger_1.ApiResponse)({
123
+ description: "Success",
124
+ status: options.httpCode,
125
+ type: options.responseType,
126
+ }),
127
+ (0, common_1.HttpCode)(options.httpCode),
128
+ ];
129
+ if (options.throttler) {
130
+ decorators.push((0, throttler_1.Throttle)({ default: options.throttler }));
131
+ }
132
+ if (options.responses) {
133
+ if (options.responses.unauthorized) {
134
+ decorators.push((0, swagger_1.ApiUnauthorizedResponse)({
135
+ description: "Unauthorized",
136
+ status: common_1.HttpStatus.UNAUTHORIZED,
137
+ type: unauthorized_dto_1.ExceptionUnauthorizedDTO,
138
+ }));
139
+ }
140
+ if (options.responses.forbidden) {
141
+ decorators.push((0, swagger_1.ApiForbiddenResponse)({
142
+ description: "Forbidden",
143
+ status: common_1.HttpStatus.FORBIDDEN,
144
+ type: forbidden_dto_1.ExceptionForbiddenDTO,
145
+ }));
146
+ }
147
+ if (options.responses.internalServerError) {
148
+ decorators.push((0, swagger_1.ApiInternalServerErrorResponse)({
149
+ description: "Internal Server Error",
150
+ status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
151
+ type: internal_server_error_dto_1.ExceptionInternalServerErrorDTO,
152
+ }));
153
+ }
154
+ if (options.responses.notFound) {
155
+ decorators.push((0, swagger_1.ApiNotFoundResponse)({
156
+ description: "Not Found",
157
+ status: common_1.HttpStatus.NOT_FOUND,
158
+ type: not_found_dto_1.ExceptionNotFoundDTO,
159
+ }));
160
+ }
161
+ if (options.responses.badRequest) {
162
+ decorators.push((0, swagger_1.ApiBadRequestResponse)({
163
+ description: "Bad Request",
164
+ status: common_1.HttpStatus.BAD_REQUEST,
165
+ type: bad_request_dto_1.ExceptionBadRequestDTO,
166
+ }));
167
+ }
168
+ if (options.responses.tooManyRequests) {
169
+ decorators.push((0, swagger_1.ApiBadRequestResponse)({
170
+ description: "Too Many Requests",
171
+ status: common_1.HttpStatus.TOO_MANY_REQUESTS,
172
+ type: too_many_requests_dto_1.ExceptionTooManyRequestsDTO,
173
+ }));
174
+ }
175
+ }
176
+ switch (options.method) {
177
+ case common_1.RequestMethod.GET: {
178
+ decorators.push((0, common_1.Get)(options.path));
179
+ break;
180
+ }
181
+ case common_1.RequestMethod.POST: {
182
+ decorators.push((0, common_1.Post)(options.path));
183
+ break;
184
+ }
185
+ case common_1.RequestMethod.PATCH: {
186
+ decorators.push((0, common_1.Patch)(options.path));
187
+ break;
188
+ }
189
+ case common_1.RequestMethod.PUT: {
190
+ decorators.push((0, common_1.Put)(options.path));
191
+ break;
192
+ }
193
+ case common_1.RequestMethod.DELETE: {
194
+ decorators.push((0, common_1.Delete)(options.path));
195
+ break;
196
+ }
197
+ default: {
198
+ throw new Error(`ApiMethod error: Method ${options.method} is not supported`);
199
+ }
200
+ }
201
+ return (0, common_1.applyDecorators)(...decorators);
202
+ }
203
+ //# sourceMappingURL=method.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.decorator.js","sourceRoot":"/","sources":["decorator/api/method.decorator.ts"],"names":[],"mappings":";;AAcA,8BAkSC;AAhTD,2CAAqH;AACrH,6CAAuL;AACvL,iDAA6C;AAE7C,qCAAwC;AAExC,yEAA6E;AAE7E,qEAA0E;AAC1E,6FAAgG;AAChG,qEAAyE;AACzE,qFAAwF;AACxF,2EAAgF;AAEhF,SAAgB,SAAS,CAA2B,OAAgC;IACnF,IAAI,OAAO,GAAW,EAAE,CAAC;IAEzB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;YACxB,KAAK,iBAAU,CAAC,KAAK,CAAC,CAAC,CAAC;gBACvB,OAAO,GA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YACxB,UAAU,CAAC,IAAI,CAAC,IAAA,YAAG,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAEnC,MAAM;QACP,CAAC;QAED,KAAK,sBAAa,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,IAAA,eAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAEtC,MAAM;QACP,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,MAAM,mBAAmB,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;IAwBD,OAAO,IAAA,wBAAe,EAAC,GAAG,UAAU,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { applyDecorators, Delete, Get, HttpCode, HttpStatus, Patch, Post, Put, RequestMethod } from \"@nestjs/common\";\nimport { ApiBadRequestResponse, ApiForbiddenResponse, ApiInternalServerErrorResponse, ApiNotFoundResponse, ApiOperation, ApiResponse, ApiUnauthorizedResponse } from \"@nestjs/swagger\";\nimport { Throttle } from \"@nestjs/throttler\";\n\nimport { EApiAction } from \"../../enum\";\nimport type { IApiBaseEntity, IApiMethodProperties } from \"../../interface\";\nimport { ExceptionBadRequestDTO } from \"../../dto/exception/bad-request.dto\";\n\nimport { ExceptionForbiddenDTO } from \"../../dto/exception/forbidden.dto\";\nimport { ExceptionInternalServerErrorDTO } from \"../../dto/exception/internal-server-error.dto\";\nimport { ExceptionNotFoundDTO } from \"../../dto/exception/not-found.dto\";\nimport { ExceptionTooManyRequestsDTO } from \"../../dto/exception/too-many-requests.dto\";\nimport { ExceptionUnauthorizedDTO } from \"../../dto/exception/unauthorized.dto\";\n\nexport function ApiMethod<T extends IApiBaseEntity>(options: IApiMethodProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void {\n\tlet summary: string = \"\";\n\n\tif (options.action) {\n\t\tswitch (options.action) {\n\t\t\tcase EApiAction.FETCH: {\n\t\t\t\tsummary = `Fetching \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.CREATE: {\n\t\t\t\tsummary = `Creating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.UPDATE: {\n\t\t\t\tsummary = `Updating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.DELETE: {\n\t\t\t\tsummary = `Deleting \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.PARTIAL_UPDATE: {\n\t\t\t\tsummary = `Partial updating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_LIST: {\n\t\t\t\tsummary = `Fetching list of \\`${options.entity.name}s\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_SPECIFIED: {\n\t\t\t\tsummary = `Fetching \\`${options.entity.name}\\` of specified item`;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.REGISTRATION: {\n\t\t\t\tsummary = `Registration of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.AUTHENTICATION: {\n\t\t\t\tsummary = `Authentication of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.CONFIRMATION: {\n\t\t\t\tsummary = `Confirmation of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.REFRESH: {\n\t\t\t\tsummary = `Refresh of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_SIMPLE_LIST: {\n\t\t\t\tsummary = `Fetching simple list of \\`${options.entity.name}s\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!options.description && options.action) {\n\t\tswitch (options.action) {\n\t\t\tcase EApiAction.FETCH: {\n\t\t\t\toptions.description = `This method is used for fetching \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.CREATE: {\n\t\t\t\toptions.description = `This method is used for creating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.UPDATE: {\n\t\t\t\toptions.description = `This method is used for updating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.DELETE: {\n\t\t\t\toptions.description = `This method is used for deleting \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.PARTIAL_UPDATE: {\n\t\t\t\toptions.description = `This method is used for partial updating \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_LIST: {\n\t\t\t\toptions.description = `This method is used for fetching list of \\`${options.entity.name}s\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_SPECIFIED: {\n\t\t\t\toptions.description = `This method is used for fetching \\`${options.entity.name}\\` of specified item`;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.REGISTRATION: {\n\t\t\t\toptions.description = `This method is used for registration of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.AUTHENTICATION: {\n\t\t\t\toptions.description = `This method is used for authentication of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.CONFIRMATION: {\n\t\t\t\toptions.description = `This method is used for confirmation of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.REFRESH: {\n\t\t\t\toptions.description = `This method is used for refresh of \\`${options.entity.name}\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase EApiAction.FETCH_SIMPLE_LIST: {\n\t\t\t\toptions.description = `This method is used for fetching simple list of \\`${options.entity.name}s\\``;\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst decorators: Array<MethodDecorator> = [\n\t\tApiOperation({ description: options.description, summary }),\n\t\tApiResponse({\n\t\t\tdescription: \"Success\",\n\t\t\tstatus: options.httpCode,\n\t\t\ttype: options.responseType,\n\t\t}),\n\t\tHttpCode(options.httpCode),\n\t];\n\n\tif (options.throttler) {\n\t\tdecorators.push(Throttle({ default: options.throttler }));\n\t}\n\n\tif (options.responses) {\n\t\tif (options.responses.unauthorized) {\n\t\t\tdecorators.push(\n\t\t\t\tApiUnauthorizedResponse({\n\t\t\t\t\tdescription: \"Unauthorized\",\n\t\t\t\t\tstatus: HttpStatus.UNAUTHORIZED,\n\t\t\t\t\ttype: ExceptionUnauthorizedDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (options.responses.forbidden) {\n\t\t\tdecorators.push(\n\t\t\t\tApiForbiddenResponse({\n\t\t\t\t\tdescription: \"Forbidden\",\n\t\t\t\t\tstatus: HttpStatus.FORBIDDEN,\n\t\t\t\t\ttype: ExceptionForbiddenDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (options.responses.internalServerError) {\n\t\t\tdecorators.push(\n\t\t\t\tApiInternalServerErrorResponse({\n\t\t\t\t\tdescription: \"Internal Server Error\",\n\t\t\t\t\tstatus: HttpStatus.INTERNAL_SERVER_ERROR,\n\t\t\t\t\ttype: ExceptionInternalServerErrorDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (options.responses.notFound) {\n\t\t\tdecorators.push(\n\t\t\t\tApiNotFoundResponse({\n\t\t\t\t\tdescription: \"Not Found\",\n\t\t\t\t\tstatus: HttpStatus.NOT_FOUND,\n\t\t\t\t\ttype: ExceptionNotFoundDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (options.responses.badRequest) {\n\t\t\tdecorators.push(\n\t\t\t\tApiBadRequestResponse({\n\t\t\t\t\tdescription: \"Bad Request\",\n\t\t\t\t\tstatus: HttpStatus.BAD_REQUEST,\n\t\t\t\t\ttype: ExceptionBadRequestDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (options.responses.tooManyRequests) {\n\t\t\tdecorators.push(\n\t\t\t\tApiBadRequestResponse({\n\t\t\t\t\tdescription: \"Too Many Requests\",\n\t\t\t\t\tstatus: HttpStatus.TOO_MANY_REQUESTS,\n\t\t\t\t\ttype: ExceptionTooManyRequestsDTO,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\tswitch (options.method) {\n\t\tcase RequestMethod.GET: {\n\t\t\tdecorators.push(Get(options.path));\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase RequestMethod.POST: {\n\t\t\tdecorators.push(Post(options.path));\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase RequestMethod.PATCH: {\n\t\t\tdecorators.push(Patch(options.path));\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase RequestMethod.PUT: {\n\t\t\tdecorators.push(Put(options.path));\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase RequestMethod.DELETE: {\n\t\t\tdecorators.push(Delete(options.path));\n\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new Error(`ApiMethod error: Method ${options.method} is not supported`);\n\t\t}\n\t}\n\n\t/* if (options.authentication) {\n switch (options.authentication) {\n case EApiAuthenticationType.USER: {\n decorators.push(ApiBearerAuth(\"userAuthorization\"), isUser());\n\n break;\n }\n\n case EApiAuthenticationType.ADMIN: {\n decorators.push(ApiBearerAuth(\"adminAuthorization\"), isAdminUser());\n\n break;\n }\n\n case EApiAuthenticationType.ACCOUNT: {\n decorators.push(ApiBearerAuth(\"accountAuthorization\"), ApiSecurity(\"accountRequestSignature\"), ApiSecurity(\"accountRequestTimestamp\"), isAccount());\n\n break;\n }\n }\n }*/\n\n\treturn applyDecorators(...decorators);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiPropertyBaseProperties } from "../../../interface";
2
+ export declare function ApiPropertyBoolean<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiPropertyBoolean = ApiPropertyBoolean;
4
+ const common_1 = require("@nestjs/common");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ const class_transformer_1 = require("class-transformer");
7
+ const class_validator_1 = require("class-validator");
8
+ function ApiPropertyBoolean(properties) {
9
+ validateOptions(properties);
10
+ const apiPropertyOptions = buildApiPropertyOptions(properties);
11
+ const decorators = buildDecorators(properties, apiPropertyOptions);
12
+ return (0, common_1.applyDecorators)(...decorators);
13
+ }
14
+ function validateOptions(options) {
15
+ const errors = [];
16
+ if (!options.response && typeof options.required !== "boolean") {
17
+ errors.push("Required is not defined");
18
+ }
19
+ if (options.response && options.required) {
20
+ errors.push("Required is defined for response");
21
+ }
22
+ if (errors.length > 0) {
23
+ throw new Error(`ApiPropertyBoolean error: ${errors.join("\n")}`);
24
+ }
25
+ }
26
+ function buildApiPropertyOptions(properties) {
27
+ const apiPropertyOptions = {
28
+ description: `${properties.entity.name} ${properties.description || ""}`,
29
+ example: true,
30
+ nullable: properties.nullable,
31
+ required: !properties.response && properties.required,
32
+ type: "boolean",
33
+ };
34
+ if (properties.isArray) {
35
+ apiPropertyOptions.isArray = true;
36
+ apiPropertyOptions.minItems = properties.minItems;
37
+ apiPropertyOptions.maxItems = properties.maxItems;
38
+ apiPropertyOptions.uniqueItems = properties.uniqueItems;
39
+ apiPropertyOptions.type = "boolean[]";
40
+ }
41
+ else {
42
+ apiPropertyOptions.type = "boolean";
43
+ }
44
+ return apiPropertyOptions;
45
+ }
46
+ function buildDecorators(properties, apiPropertyOptions) {
47
+ const decorators = [(0, swagger_1.ApiProperty)(apiPropertyOptions)];
48
+ if (properties.response) {
49
+ decorators.push(swagger_1.ApiResponseProperty);
50
+ if (properties.expose) {
51
+ decorators.push((0, class_transformer_1.Expose)());
52
+ }
53
+ }
54
+ else if (properties.isArray) {
55
+ if (!properties.required) {
56
+ decorators.push((0, class_validator_1.IsOptional)());
57
+ }
58
+ decorators.push((0, class_validator_1.IsArray)(), (0, class_validator_1.ArrayNotEmpty)());
59
+ if (properties.minItems) {
60
+ decorators.push((0, class_validator_1.ArrayMinSize)(properties.minItems));
61
+ }
62
+ if (properties.maxItems) {
63
+ decorators.push((0, class_validator_1.ArrayMaxSize)(properties.maxItems));
64
+ }
65
+ decorators.push((0, class_validator_1.IsBoolean)({ each: true }));
66
+ }
67
+ else {
68
+ if (!properties.required) {
69
+ decorators.push((0, class_validator_1.IsOptional)());
70
+ }
71
+ decorators.push((0, class_validator_1.IsBoolean)(), (0, class_transformer_1.Transform)(({ value }) => {
72
+ return value === "true" || value === true || value === 1 || value === "1";
73
+ }));
74
+ }
75
+ return decorators;
76
+ }
77
+ //# sourceMappingURL=boolean.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.decorator.js","sourceRoot":"/","sources":["decorator/api/property/boolean.decorator.ts"],"names":[],"mappings":";;AASA,gDAOC;AAhBD,2CAAiD;AAGjD,6CAAmE;AACnE,yDAAsD;AAEtD,qDAA4G;AAG5G,SAAgB,kBAAkB,CAA2B,UAAyC;IACrG,eAAe,CAAI,UAAU,CAAC,CAAC;IAE/B,MAAM,kBAAkB,GAAuB,uBAAuB,CAAI,UAAU,CAAC,CAAC;IACtF,MAAM,UAAU,GAA6B,eAAe,CAAI,UAAU,EAAE,kBAAkB,CAAC,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QAC/B,CAAC;QAED,UAAU,CAAC,IAAI,CACd,IAAA,2BAAS,GAAE,EACX,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAO,EAAE,EAAE;YAC5B,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,GAAG,CAAC;QAC3E,CAAC,CAAC,CACF,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\n\nimport type { ApiPropertyOptions} from \"@nestjs/swagger\";\nimport { ApiProperty, ApiResponseProperty } from \"@nestjs/swagger\";\nimport { Expose, Transform } from \"class-transformer\";\n\nimport { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, IsArray, IsBoolean, IsOptional } from \"class-validator\";\nimport type { IApiBaseEntity, IApiPropertyBaseProperties } from \"../../../interface\";\n\nexport function ApiPropertyBoolean<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tvalidateOptions<T>(properties);\n\n\tconst apiPropertyOptions: ApiPropertyOptions = buildApiPropertyOptions<T>(properties);\n\tconst decorators: Array<PropertyDecorator> = buildDecorators<T>(properties, apiPropertyOptions);\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(options: IApiPropertyBaseProperties<T>): void {\n\tconst errors: Array<string> = [];\n\n\tif (!options.response && typeof options.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (options.response && options.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`ApiPropertyBoolean error: ${errors.join(\"\\n\")}`);\n\t}\n}\n\nfunction buildApiPropertyOptions<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>): ApiPropertyOptions {\n\tconst apiPropertyOptions: ApiPropertyOptions = {\n\t\tdescription: `${properties.entity.name} ${properties.description || \"\"}`,\n\t\texample: true,\n\t\tnullable: properties.nullable,\n\t\trequired: !properties.response && properties.required,\n\t\ttype: \"boolean\",\n\t};\n\n\tif (properties.isArray) {\n\t\tapiPropertyOptions.isArray = true;\n\t\tapiPropertyOptions.minItems = properties.minItems;\n\t\tapiPropertyOptions.maxItems = properties.maxItems;\n\t\tapiPropertyOptions.uniqueItems = properties.uniqueItems;\n\t\tapiPropertyOptions.type = \"boolean[]\";\n\t} else {\n\t\tapiPropertyOptions.type = \"boolean\";\n\t}\n\n\treturn apiPropertyOptions;\n}\n\nfunction buildDecorators<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>, apiPropertyOptions: ApiPropertyOptions): Array<PropertyDecorator> {\n\tconst decorators: Array<PropertyDecorator> = [ApiProperty(apiPropertyOptions)];\n\n\tif (properties.response) {\n\t\tdecorators.push(ApiResponseProperty);\n\n\t\tif (properties.expose) {\n\t\t\tdecorators.push(Expose());\n\t\t}\n\t} else if (properties.isArray) {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tdecorators.push(IsArray(), ArrayNotEmpty());\n\n\t\tif (properties.minItems) {\n\t\t\tdecorators.push(ArrayMinSize(properties.minItems));\n\t\t}\n\n\t\tif (properties.maxItems) {\n\t\t\tdecorators.push(ArrayMaxSize(properties.maxItems));\n\t\t}\n\n\t\tdecorators.push(IsBoolean({ each: true }));\n\t} else {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tdecorators.push(\n\t\t\tIsBoolean(),\n\t\t\tTransform(({ value }: any) => {\n\t\t\t\treturn value === \"true\" || value === true || value === 1 || value === \"1\";\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn decorators;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiPropertyDateProperties } from "../../../interface";
2
+ export declare function ApiPropertyDate<T extends IApiBaseEntity>(properties: IApiPropertyDateProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;