itlab-internal-services 2.15.7 → 2.16.1

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 (371) hide show
  1. package/README.md +1 -187
  2. package/dist/classes/document-merger.class.js +2 -3
  3. package/dist/classes/index.d.ts +4 -1
  4. package/dist/classes/index.js +7 -3
  5. package/dist/classes/report-category.class.d.ts +55 -0
  6. package/dist/classes/report-category.class.js +120 -0
  7. package/dist/classes/schema-builder.class.d.ts +75 -0
  8. package/dist/classes/schema-builder.class.js +109 -0
  9. package/dist/classes/task-manager.class.d.ts +71 -0
  10. package/dist/classes/task-manager.class.js +99 -0
  11. package/dist/decorators/{account.decorator.d.ts → authenticated-account.decorator.d.ts} +4 -4
  12. package/dist/decorators/{account.decorator.js → authenticated-account.decorator.js} +8 -10
  13. package/dist/decorators/index.d.ts +1 -1
  14. package/dist/decorators/index.js +1 -1
  15. package/dist/exceptions/authenticated-user-required.exception.d.ts +34 -0
  16. package/dist/exceptions/authenticated-user-required.exception.js +51 -0
  17. package/dist/exceptions/bad-body.exception.d.ts +19 -8
  18. package/dist/exceptions/bad-body.exception.js +26 -10
  19. package/dist/exceptions/bad-parameter.exception.d.ts +23 -8
  20. package/dist/exceptions/bad-parameter.exception.js +41 -18
  21. package/dist/exceptions/duplicate.exception.d.ts +20 -8
  22. package/dist/exceptions/duplicate.exception.js +27 -10
  23. package/dist/exceptions/index.d.ts +1 -0
  24. package/dist/exceptions/index.js +1 -0
  25. package/dist/functions/add-views-likes-virtuals.function.d.ts +15 -0
  26. package/dist/functions/add-views-likes-virtuals.function.js +43 -0
  27. package/dist/functions/create-internal-axios-client.function.js +2 -2
  28. package/dist/functions/index.d.ts +1 -0
  29. package/dist/functions/index.js +3 -1
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.js +5 -5
  32. package/dist/interceptors/attribute-sanitizer.interceptor.d.ts +68 -0
  33. package/dist/interceptors/attribute-sanitizer.interceptor.js +154 -0
  34. package/dist/interceptors/index.d.ts +1 -0
  35. package/dist/interceptors/index.js +17 -0
  36. package/dist/middleware/http-logging.middleware.d.ts +19 -0
  37. package/dist/middleware/http-logging.middleware.js +50 -0
  38. package/dist/middleware/index.d.ts +1 -0
  39. package/dist/middleware/index.js +17 -0
  40. package/dist/models/account.model.d.ts +23 -0
  41. package/dist/models/account.model.js +59 -0
  42. package/dist/models/index.d.ts +3 -1
  43. package/dist/models/index.js +7 -3
  44. package/dist/{modules/search/models → models}/search-document.model.d.ts +1 -1
  45. package/dist/{modules/search/models → models}/search-document.model.js +1 -1
  46. package/dist/models/{account-entity.model.d.ts → user.model.d.ts} +8 -21
  47. package/dist/models/{account-entity.model.js → user.model.js} +11 -25
  48. package/dist/modules/authentication/authentication-module-options.interface.d.ts +2 -8
  49. package/dist/modules/authentication/authentication-options.parameter.d.ts +4 -0
  50. package/dist/modules/authentication/{inject-auth-options.decorator.js → authentication-options.parameter.js} +5 -2
  51. package/dist/modules/authentication/authentication.module.d.ts +23 -0
  52. package/dist/modules/authentication/authentication.module.js +24 -1
  53. package/dist/modules/authentication/guards/index.d.ts +2 -2
  54. package/dist/modules/authentication/guards/index.js +7 -7
  55. package/dist/modules/authentication/guards/jwt-auth.guard.d.ts +17 -0
  56. package/dist/modules/authentication/guards/jwt-auth.guard.js +67 -0
  57. package/dist/modules/authentication/guards/permissions.guard.d.ts +5 -27
  58. package/dist/modules/authentication/guards/permissions.guard.js +27 -59
  59. package/dist/modules/authentication/guards/public.guard.d.ts +7 -13
  60. package/dist/modules/authentication/guards/public.guard.js +10 -24
  61. package/dist/modules/authentication/guards/service-auth.guard.d.ts +22 -0
  62. package/dist/modules/authentication/guards/service-auth.guard.js +65 -0
  63. package/dist/modules/authentication/index.d.ts +3 -3
  64. package/dist/modules/authentication/index.js +3 -5
  65. package/dist/modules/cache/cache-response.interceptor.d.ts +2 -2
  66. package/dist/modules/cache/cache-response.interceptor.js +2 -2
  67. package/dist/modules/cache/index.d.ts +1 -0
  68. package/dist/modules/cache/index.js +1 -0
  69. package/dist/modules/comment/comment-module-options.interface.d.ts +38 -0
  70. package/dist/modules/comment/comment.controller.d.ts +24 -30
  71. package/dist/modules/comment/comment.controller.js +59 -61
  72. package/dist/modules/comment/comment.module-definition.d.ts +1 -42
  73. package/dist/modules/comment/comment.module-definition.js +1 -2
  74. package/dist/modules/comment/comment.module.d.ts +13 -13
  75. package/dist/modules/comment/comment.module.js +15 -42
  76. package/dist/modules/comment/comment.service.d.ts +27 -37
  77. package/dist/modules/comment/comment.service.js +50 -84
  78. package/dist/modules/comment/index.d.ts +2 -3
  79. package/dist/modules/comment/index.js +16 -7
  80. package/dist/modules/database/database.module.js +2 -5
  81. package/dist/modules/database/index.d.ts +2 -5
  82. package/dist/modules/database/index.js +17 -9
  83. package/dist/modules/index.d.ts +2 -6
  84. package/dist/modules/index.js +2 -6
  85. package/dist/modules/like/index.d.ts +2 -1
  86. package/dist/modules/like/index.js +16 -3
  87. package/dist/modules/like/like-module-options.interface.d.ts +21 -0
  88. package/dist/modules/like/like.controller.d.ts +45 -37
  89. package/dist/modules/like/like.controller.js +117 -102
  90. package/dist/modules/like/like.module-definition.d.ts +1 -17
  91. package/dist/modules/like/like.module-definition.js +1 -2
  92. package/dist/modules/like/like.module.d.ts +12 -12
  93. package/dist/modules/like/like.module.js +14 -37
  94. package/dist/modules/like/like.service.d.ts +31 -27
  95. package/dist/modules/like/like.service.js +42 -35
  96. package/dist/modules/merge/index.d.ts +3 -0
  97. package/dist/modules/merge/index.js +19 -0
  98. package/dist/modules/merge/merge-module-options.interface.d.ts +21 -0
  99. package/dist/modules/merge/merge.controller.d.ts +30 -0
  100. package/dist/modules/merge/merge.controller.js +76 -0
  101. package/dist/modules/merge/merge.module.d.ts +18 -0
  102. package/dist/modules/merge/merge.module.js +41 -0
  103. package/dist/modules/merge/merge.service.interface.d.ts +17 -0
  104. package/dist/modules/services/base-http.service.d.ts +83 -0
  105. package/dist/modules/services/base-http.service.js +124 -0
  106. package/dist/modules/services/base-urls.d.ts +22 -0
  107. package/dist/modules/services/base-urls.js +121 -0
  108. package/dist/modules/services/index.d.ts +4 -0
  109. package/dist/modules/services/index.js +20 -0
  110. package/dist/modules/services/providers/accounts.service.d.ts +52 -0
  111. package/dist/modules/services/providers/accounts.service.js +84 -0
  112. package/dist/modules/services/providers/books.service.d.ts +29 -0
  113. package/dist/modules/services/providers/books.service.js +55 -0
  114. package/dist/modules/services/providers/changelog.service.d.ts +18 -0
  115. package/dist/modules/services/providers/changelog.service.js +43 -0
  116. package/dist/modules/services/providers/comments/comments.service-definition.d.ts +1 -0
  117. package/dist/modules/services/providers/comments/comments.service-definition.js +4 -0
  118. package/dist/modules/services/providers/comments/comments.service.d.ts +60 -0
  119. package/dist/modules/services/providers/comments/comments.service.js +139 -0
  120. package/dist/modules/services/providers/comments/index.d.ts +1 -0
  121. package/dist/{factories → modules/services/providers/comments}/index.js +1 -1
  122. package/dist/modules/services/providers/content/content-return-types.d.ts +19 -0
  123. package/dist/modules/services/providers/content/content-return-types.js +7 -0
  124. package/dist/modules/services/providers/content/content.service-definition.d.ts +1 -0
  125. package/dist/modules/services/providers/content/content.service-definition.js +4 -0
  126. package/dist/modules/services/providers/content/content.service.d.ts +96 -0
  127. package/dist/modules/services/providers/content/content.service.js +231 -0
  128. package/dist/modules/services/providers/content/index.d.ts +2 -0
  129. package/dist/modules/{search/models → services/providers/content}/index.js +1 -1
  130. package/dist/modules/services/providers/demo-hive.service.d.ts +29 -0
  131. package/dist/modules/services/providers/demo-hive.service.js +55 -0
  132. package/dist/modules/services/providers/events.service.d.ts +29 -0
  133. package/dist/modules/services/providers/events.service.js +55 -0
  134. package/dist/modules/services/providers/hackschool.service.d.ts +49 -0
  135. package/dist/modules/services/providers/hackschool.service.js +79 -0
  136. package/dist/modules/services/providers/ideas.service.d.ts +18 -0
  137. package/dist/modules/services/providers/ideas.service.js +43 -0
  138. package/dist/modules/services/providers/index.d.ts +19 -0
  139. package/dist/modules/services/providers/index.js +35 -0
  140. package/dist/modules/services/providers/lunch-roulette.service.d.ts +18 -0
  141. package/dist/modules/services/providers/lunch-roulette.service.js +43 -0
  142. package/dist/modules/services/providers/mail/index.d.ts +3 -0
  143. package/dist/modules/services/providers/mail/index.js +19 -0
  144. package/dist/modules/services/providers/mail/mail-types.d.ts +30 -0
  145. package/dist/modules/services/providers/mail/mail-types.js +22 -0
  146. package/dist/modules/services/providers/mail/mail.service.d.ts +99 -0
  147. package/dist/modules/{mail → services/providers/mail}/mail.service.js +55 -92
  148. package/dist/modules/services/providers/newletter.service.d.ts +29 -0
  149. package/dist/modules/services/providers/newletter.service.js +55 -0
  150. package/dist/modules/services/providers/newsroom.service.d.ts +47 -0
  151. package/dist/modules/services/providers/newsroom.service.js +73 -0
  152. package/dist/modules/services/providers/notification/dtos/schedule-notification.dto.js +2 -0
  153. package/dist/modules/services/providers/notification/index.d.ts +2 -0
  154. package/dist/modules/services/providers/notification/index.js +18 -0
  155. package/dist/modules/services/providers/notification/notification.service-definition.d.ts +1 -0
  156. package/dist/modules/services/providers/notification/notification.service-definition.js +4 -0
  157. package/dist/modules/services/providers/notification/notification.service.d.ts +50 -0
  158. package/dist/modules/services/providers/notification/notification.service.js +130 -0
  159. package/dist/modules/services/providers/pass/dtos/create-guild-member-pass.dto.js +2 -0
  160. package/dist/modules/services/providers/pass/dtos/create-team-member-pass.dto.js +2 -0
  161. package/dist/modules/services/providers/pass/index.d.ts +2 -0
  162. package/dist/modules/services/providers/pass/index.js +18 -0
  163. package/dist/modules/services/providers/pass/pass-types.d.ts +18 -0
  164. package/dist/modules/services/providers/pass/pass-types.js +7 -0
  165. package/dist/modules/{pass → services/providers/pass}/pass.service.d.ts +15 -39
  166. package/dist/modules/{pass → services/providers/pass}/pass.service.js +46 -61
  167. package/dist/modules/services/providers/podcasts.service.d.ts +29 -0
  168. package/dist/modules/services/providers/podcasts.service.js +55 -0
  169. package/dist/modules/services/providers/search/dtos/index-search-document.dto.js +2 -0
  170. package/dist/modules/services/providers/search/index.d.ts +2 -0
  171. package/dist/modules/services/providers/search/index.js +18 -0
  172. package/dist/modules/services/providers/search/search.service-definition.d.ts +1 -0
  173. package/dist/modules/services/providers/search/search.service-definition.js +4 -0
  174. package/dist/modules/services/providers/search/search.service.d.ts +66 -0
  175. package/dist/modules/services/providers/search/search.service.js +171 -0
  176. package/dist/modules/services/providers/team.service.d.ts +29 -0
  177. package/dist/modules/services/providers/team.service.js +55 -0
  178. package/dist/modules/services/providers/tech-radar.service.d.ts +39 -0
  179. package/dist/modules/services/providers/tech-radar.service.js +67 -0
  180. package/dist/modules/services/services-module-options.interface.d.ts +4 -0
  181. package/dist/modules/services/services-module-options.interface.js +2 -0
  182. package/dist/modules/services/services-options.parameter.d.ts +1 -0
  183. package/dist/modules/services/services-options.parameter.js +8 -0
  184. package/dist/modules/services/services.module-definition.d.ts +16 -0
  185. package/dist/modules/services/services.module-definition.js +21 -0
  186. package/dist/modules/services/services.module.d.ts +17 -0
  187. package/dist/modules/services/services.module.js +63 -0
  188. package/dist/pipes/index.d.ts +2 -3
  189. package/dist/pipes/index.js +2 -3
  190. package/dist/pipes/params/hub-id.pipe.d.ts +22 -0
  191. package/dist/pipes/{hub-id.pipe.js → params/hub-id.pipe.js} +14 -17
  192. package/dist/pipes/params/hub-resource.pipe.d.ts +22 -0
  193. package/dist/pipes/{hub-resource.pipe.js → params/hub-resource.pipe.js} +19 -20
  194. package/dist/pipes/params/index.d.ts +3 -0
  195. package/dist/pipes/params/index.js +19 -0
  196. package/dist/pipes/params/mongo-id.pipe.d.ts +15 -0
  197. package/dist/pipes/params/mongo-id.pipe.js +52 -0
  198. package/dist/pipes/queries/index.d.ts +3 -0
  199. package/dist/pipes/queries/index.js +19 -0
  200. package/dist/pipes/queries/mongo-ids.pipe.d.ts +22 -0
  201. package/dist/pipes/queries/mongo-ids.pipe.js +60 -0
  202. package/dist/pipes/queries/optional-boolean.pipe.d.ts +29 -0
  203. package/dist/pipes/queries/optional-boolean.pipe.js +72 -0
  204. package/dist/pipes/queries/optional-include-drafts.pipe.d.ts +28 -0
  205. package/dist/pipes/queries/optional-include-drafts.pipe.js +38 -0
  206. package/dist/properties/content-return-type.property.d.ts +7 -0
  207. package/dist/properties/content-return-type.property.js +22 -0
  208. package/dist/properties/index.d.ts +4 -0
  209. package/dist/properties/index.js +11 -0
  210. package/dist/properties/likeable.properties.d.ts +1 -0
  211. package/dist/properties/likeable.properties.js +66 -0
  212. package/dist/properties/viewable.properties.d.ts +1 -0
  213. package/dist/properties/viewable.properties.js +66 -0
  214. package/dist/swagger/index.d.ts +1 -0
  215. package/dist/swagger/index.js +5 -0
  216. package/dist/swagger/remove-public-route-auth.plugin.d.ts +9 -0
  217. package/dist/swagger/remove-public-route-auth.plugin.js +25 -0
  218. package/dist/swagger/swagger-options.interface.d.ts +14 -0
  219. package/dist/swagger/swagger-options.interface.js +2 -0
  220. package/dist/swagger/swagger.function.d.ts +11 -0
  221. package/dist/swagger/swagger.function.js +47 -0
  222. package/dist/transform/boolean.transform.js +3 -3
  223. package/dist/types/index.d.ts +2 -0
  224. package/dist/types/index.js +18 -0
  225. package/dist/types/likeable.type.d.ts +15 -0
  226. package/dist/types/likeable.type.js +2 -0
  227. package/dist/types/viewable.type.d.ts +15 -0
  228. package/dist/types/viewable.type.js +2 -0
  229. package/package.json +2 -2
  230. package/dist/classes/document-updater.class.d.ts +0 -39
  231. package/dist/classes/document-updater.class.js +0 -57
  232. package/dist/factories/index.d.ts +0 -1
  233. package/dist/factories/virtuals.factory.d.ts +0 -79
  234. package/dist/factories/virtuals.factory.js +0 -171
  235. package/dist/http-logger.middleware.d.ts +0 -12
  236. package/dist/http-logger.middleware.js +0 -43
  237. package/dist/likeable.interface.d.ts +0 -41
  238. package/dist/likeable.interface.js +0 -48
  239. package/dist/modules/authentication/guards/auth.guard.d.ts +0 -36
  240. package/dist/modules/authentication/guards/auth.guard.js +0 -107
  241. package/dist/modules/authentication/guards/internal.guard.d.ts +0 -33
  242. package/dist/modules/authentication/guards/internal.guard.js +0 -72
  243. package/dist/modules/authentication/inject-auth-options.decorator.d.ts +0 -1
  244. package/dist/modules/comment/comment.model.d.ts +0 -29
  245. package/dist/modules/comment/comment.model.js +0 -43
  246. package/dist/modules/content/content.module-definition.d.ts +0 -5
  247. package/dist/modules/content/content.module-definition.js +0 -8
  248. package/dist/modules/content/content.module.d.ts +0 -31
  249. package/dist/modules/content/content.module.js +0 -60
  250. package/dist/modules/content/content.service.d.ts +0 -50
  251. package/dist/modules/content/content.service.js +0 -145
  252. package/dist/modules/content/index.d.ts +0 -3
  253. package/dist/modules/content/index.js +0 -9
  254. package/dist/modules/database/model-service/dbs/hub-account.db.d.ts +0 -28
  255. package/dist/modules/database/model-service/dbs/hub-account.db.js +0 -44
  256. package/dist/modules/database/model-service/dbs/hub-books.db.d.ts +0 -23
  257. package/dist/modules/database/model-service/dbs/hub-books.db.js +0 -45
  258. package/dist/modules/database/model-service/dbs/hub-comments.db.d.ts +0 -29
  259. package/dist/modules/database/model-service/dbs/hub-comments.db.js +0 -68
  260. package/dist/modules/database/model-service/dbs/hub-content.db.d.ts +0 -24
  261. package/dist/modules/database/model-service/dbs/hub-content.db.js +0 -49
  262. package/dist/modules/database/model-service/dbs/hub-demo-hive.db.d.ts +0 -23
  263. package/dist/modules/database/model-service/dbs/hub-demo-hive.db.js +0 -45
  264. package/dist/modules/database/model-service/dbs/hub-events.db.d.ts +0 -24
  265. package/dist/modules/database/model-service/dbs/hub-events.db.js +0 -49
  266. package/dist/modules/database/model-service/dbs/hub-hackschool.db.d.ts +0 -60
  267. package/dist/modules/database/model-service/dbs/hub-hackschool.db.js +0 -106
  268. package/dist/modules/database/model-service/dbs/hub-newsroom.db.d.ts +0 -25
  269. package/dist/modules/database/model-service/dbs/hub-newsroom.db.js +0 -53
  270. package/dist/modules/database/model-service/dbs/hub-podcasts.db.d.ts +0 -23
  271. package/dist/modules/database/model-service/dbs/hub-podcasts.db.js +0 -45
  272. package/dist/modules/database/model-service/dbs/hub-team.db.d.ts +0 -22
  273. package/dist/modules/database/model-service/dbs/hub-team.db.js +0 -41
  274. package/dist/modules/database/model-service/dbs/hub-tech-radar.db.d.ts +0 -42
  275. package/dist/modules/database/model-service/dbs/hub-tech-radar.db.js +0 -81
  276. package/dist/modules/database/model-service/model.service.d.ts +0 -6407
  277. package/dist/modules/database/model-service/model.service.js +0 -136
  278. package/dist/modules/database/populate-service/populate.service.d.ts +0 -73
  279. package/dist/modules/database/populate-service/populate.service.js +0 -163
  280. package/dist/modules/database/service-mapper-service/service-mapper.service.d.ts +0 -32
  281. package/dist/modules/database/service-mapper-service/service-mapper.service.js +0 -73
  282. package/dist/modules/fetch/fetch.module.d.ts +0 -31
  283. package/dist/modules/fetch/fetch.module.js +0 -60
  284. package/dist/modules/fetch/fetch.service.d.ts +0 -153
  285. package/dist/modules/fetch/fetch.service.js +0 -274
  286. package/dist/modules/fetch/index.d.ts +0 -2
  287. package/dist/modules/fetch/index.js +0 -7
  288. package/dist/modules/mail/index.d.ts +0 -4
  289. package/dist/modules/mail/index.js +0 -23
  290. package/dist/modules/mail/mail.module.d.ts +0 -31
  291. package/dist/modules/mail/mail.module.js +0 -60
  292. package/dist/modules/mail/mail.service.d.ts +0 -136
  293. package/dist/modules/notification/index.d.ts +0 -3
  294. package/dist/modules/notification/index.js +0 -22
  295. package/dist/modules/notification/notification.module-definition.d.ts +0 -5
  296. package/dist/modules/notification/notification.module-definition.js +0 -8
  297. package/dist/modules/notification/notification.module.d.ts +0 -34
  298. package/dist/modules/notification/notification.module.js +0 -63
  299. package/dist/modules/notification/notification.service.d.ts +0 -42
  300. package/dist/modules/notification/notification.service.js +0 -100
  301. package/dist/modules/pass/index.d.ts +0 -3
  302. package/dist/modules/pass/index.js +0 -22
  303. package/dist/modules/pass/pass.module.d.ts +0 -32
  304. package/dist/modules/pass/pass.module.js +0 -61
  305. package/dist/modules/search/index.d.ts +0 -4
  306. package/dist/modules/search/index.js +0 -23
  307. package/dist/modules/search/models/index.d.ts +0 -1
  308. package/dist/modules/search/search.module-definition.d.ts +0 -5
  309. package/dist/modules/search/search.module-definition.js +0 -8
  310. package/dist/modules/search/search.module.d.ts +0 -33
  311. package/dist/modules/search/search.module.js +0 -62
  312. package/dist/modules/search/search.service.d.ts +0 -49
  313. package/dist/modules/search/search.service.js +0 -120
  314. package/dist/pipes/hub-id.pipe.d.ts +0 -22
  315. package/dist/pipes/hub-resource.pipe.d.ts +0 -22
  316. package/dist/pipes/mongo-id.pipe.d.ts +0 -14
  317. package/dist/pipes/mongo-id.pipe.js +0 -52
  318. package/dist/swagger.config.d.ts +0 -36
  319. package/dist/swagger.config.js +0 -76
  320. package/dist/viewable.interface.d.ts +0 -41
  321. package/dist/viewable.interface.js +0 -48
  322. /package/dist/modules/{mail/dtos/auth-login-token-mail.dto.js → comment/comment-module-options.interface.js} +0 -0
  323. /package/dist/modules/{mail/dtos/auth-password-reset-mail.dto.js → like/like-module-options.interface.js} +0 -0
  324. /package/dist/modules/{mail/dtos/event-cancel-mail.dto.js → merge/merge-module-options.interface.js} +0 -0
  325. /package/dist/modules/{mail/dtos/event-invite-mail.dto.js → merge/merge.service.interface.js} +0 -0
  326. /package/dist/modules/{mail → services/providers/mail}/dtos/auth-login-token-mail.dto.d.ts +0 -0
  327. /package/dist/modules/{mail/dtos/idea-status-updated-mail.dto.js → services/providers/mail/dtos/auth-login-token-mail.dto.js} +0 -0
  328. /package/dist/modules/{mail → services/providers/mail}/dtos/auth-password-reset-mail.dto.d.ts +0 -0
  329. /package/dist/modules/{mail/dtos/idea-submitted-mail.dto.js → services/providers/mail/dtos/auth-password-reset-mail.dto.js} +0 -0
  330. /package/dist/modules/{mail → services/providers/mail}/dtos/event-cancel-mail.dto.d.ts +0 -0
  331. /package/dist/modules/{mail/dtos/lunch-roulette-cancel-mail.dto.js → services/providers/mail/dtos/event-cancel-mail.dto.js} +0 -0
  332. /package/dist/modules/{mail → services/providers/mail}/dtos/event-invite-mail.dto.d.ts +0 -0
  333. /package/dist/modules/{mail/dtos/lunch-roulette-matched-mail.dto.js → services/providers/mail/dtos/event-invite-mail.dto.js} +0 -0
  334. /package/dist/modules/{mail → services/providers/mail}/dtos/idea-status-updated-mail.dto.d.ts +0 -0
  335. /package/dist/modules/{mail/dtos/lunch-roulette-submitted-mail.dto.js → services/providers/mail/dtos/idea-status-updated-mail.dto.js} +0 -0
  336. /package/dist/modules/{mail → services/providers/mail}/dtos/idea-submitted-mail.dto.d.ts +0 -0
  337. /package/dist/modules/{mail/dtos/lunch-roulette-unmatched-mail.dto.js → services/providers/mail/dtos/idea-submitted-mail.dto.js} +0 -0
  338. /package/dist/modules/{mail → services/providers/mail}/dtos/index.d.ts +0 -0
  339. /package/dist/modules/{mail → services/providers/mail}/dtos/index.js +0 -0
  340. /package/dist/modules/{mail → services/providers/mail}/dtos/lunch-roulette-cancel-mail.dto.d.ts +0 -0
  341. /package/dist/modules/{mail/dtos/newsletter-issue-mail.dto.js → services/providers/mail/dtos/lunch-roulette-cancel-mail.dto.js} +0 -0
  342. /package/dist/modules/{mail → services/providers/mail}/dtos/lunch-roulette-matched-mail.dto.d.ts +0 -0
  343. /package/dist/modules/{mail/dtos/newsletter-subscribed-mail.dto.js → services/providers/mail/dtos/lunch-roulette-matched-mail.dto.js} +0 -0
  344. /package/dist/modules/{mail → services/providers/mail}/dtos/lunch-roulette-submitted-mail.dto.d.ts +0 -0
  345. /package/dist/modules/{mail/dtos/newsletter-unsubscribed-mail.dto.js → services/providers/mail/dtos/lunch-roulette-submitted-mail.dto.js} +0 -0
  346. /package/dist/modules/{mail → services/providers/mail}/dtos/lunch-roulette-unmatched-mail.dto.d.ts +0 -0
  347. /package/dist/modules/{mail/dtos/notification-mail.dto.js → services/providers/mail/dtos/lunch-roulette-unmatched-mail.dto.js} +0 -0
  348. /package/dist/modules/{mail → services/providers/mail}/dtos/newsletter-issue-mail.dto.d.ts +0 -0
  349. /package/dist/modules/{notification/dtos/schedule-notification.dto.js → services/providers/mail/dtos/newsletter-issue-mail.dto.js} +0 -0
  350. /package/dist/modules/{mail → services/providers/mail}/dtos/newsletter-subscribed-mail.dto.d.ts +0 -0
  351. /package/dist/modules/{pass/dtos/create-guild-member-pass.dto.js → services/providers/mail/dtos/newsletter-subscribed-mail.dto.js} +0 -0
  352. /package/dist/modules/{mail → services/providers/mail}/dtos/newsletter-unsubscribed-mail.dto.d.ts +0 -0
  353. /package/dist/modules/{pass/dtos/create-team-member-pass.dto.js → services/providers/mail/dtos/newsletter-unsubscribed-mail.dto.js} +0 -0
  354. /package/dist/modules/{mail → services/providers/mail}/dtos/notification-mail.dto.d.ts +0 -0
  355. /package/dist/modules/{search/dtos/index-search-document.dto.js → services/providers/mail/dtos/notification-mail.dto.js} +0 -0
  356. /package/dist/modules/{mail → services/providers/mail}/models/index.d.ts +0 -0
  357. /package/dist/modules/{mail → services/providers/mail}/models/index.js +0 -0
  358. /package/dist/modules/{mail → services/providers/mail}/models/mail-recipient.model.d.ts +0 -0
  359. /package/dist/modules/{mail → services/providers/mail}/models/mail-recipient.model.js +0 -0
  360. /package/dist/modules/{notification → services/providers/notification}/dtos/index.d.ts +0 -0
  361. /package/dist/modules/{notification → services/providers/notification}/dtos/index.js +0 -0
  362. /package/dist/modules/{notification → services/providers/notification}/dtos/schedule-notification.dto.d.ts +0 -0
  363. /package/dist/modules/{pass → services/providers/pass}/dtos/create-guild-member-pass.dto.d.ts +0 -0
  364. /package/dist/modules/{pass → services/providers/pass}/dtos/create-team-member-pass.dto.d.ts +0 -0
  365. /package/dist/modules/{pass → services/providers/pass}/dtos/index.d.ts +0 -0
  366. /package/dist/modules/{pass → services/providers/pass}/dtos/index.js +0 -0
  367. /package/dist/modules/{search → services/providers/search}/dtos/index-search-document.dto.d.ts +0 -0
  368. /package/dist/modules/{search → services/providers/search}/dtos/index.d.ts +0 -0
  369. /package/dist/modules/{search → services/providers/search}/dtos/index.js +0 -0
  370. /package/dist/{modules/content → properties}/content.property.d.ts +0 -0
  371. /package/dist/{modules/content → properties}/content.property.js +0 -0
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # IT Lab Internal Services
2
+
2
3
  > Diese Library funktioniert nur mit NestJs
3
4
 
4
5
  [![npm version](https://img.shields.io/npm/v/itlab-internal-services.svg?style=flat-square)](https://www.npmjs.org/package/itlab-internal-services)
@@ -17,190 +18,3 @@ To begin using it, we first install the required dependency.
17
18
  ```bash
18
19
  yarn add itlab-internal-services
19
20
  ```
20
-
21
- ### Getting started
22
-
23
- Once the installation process is complete, to use the `InternalServices`, first import `InternalModule`.
24
-
25
- ```typescript
26
- @Module({
27
- imports: [InternalModule],
28
- providers: [NewsService],
29
- })
30
- export class NewsModule {}
31
- ```
32
-
33
- Next, inject `CommentService`, `ContentService` or `SearchService` using normal constructor injection.
34
-
35
- > **Hint** `InternalModule`, `CommentService`, `ContentService` & `SearchService` are imported from `itlab-internal-services` package.
36
-
37
- ```typescript
38
- @Injectable()
39
- export class NewsService {
40
- constructor(
41
- private readonly commentService: CommentService,
42
- private readonly contentService: ContentService,
43
- private readonly searchService: SearchService,
44
- ) {}
45
- }
46
- ```
47
-
48
- ### Comment Service
49
- ```typescript
50
- async post(targetId: string, authorId: string, comment: Comment): Promise<Comment>
51
- ```
52
-
53
- ```typescript
54
- async delete(targetId: string): Promise<void>
55
- ```
56
-
57
- ### Content Service
58
-
59
- ```typescript
60
- async verify(content: Content): Promise<void>
61
- ```
62
-
63
- ```typescript
64
- async post(targetId: string, content: Content): Promise<void>
65
- ```
66
-
67
- ```typescript
68
- async delete(targetId: string): Promise<void>
69
- ```
70
-
71
- ### Pipes
72
- ```typescript
73
- @Controller("news")
74
- export class NewsController {
75
-
76
- @ApiTarget("target")
77
- @Get(":target")
78
- getNews(@Target("target") target: string) {}
79
-
80
- }
81
- ```
82
-
83
- ```typescript
84
- @Controller("news")
85
- export class NewsController {
86
-
87
- @ApiHid("hid")
88
- @Get(":hid")
89
- getNews(@Hid("hid") hid: string) {}
90
-
91
- }
92
- ```
93
-
94
- ```typescript
95
- @Controller("news")
96
- export class NewsController {
97
-
98
- @ApiId("id")
99
- @Get(":id")
100
- getNews(@Id("id") id: string) {}
101
-
102
- }
103
- ```
104
-
105
- ### Guards
106
- ```typescript
107
- @Internal()
108
- @Controller()
109
- export class NewsController {}
110
- ```
111
-
112
- ```typescript
113
- @Jwt()
114
- @Controller()
115
- export class NewsController {
116
- @Get("")
117
- getNews(@Account() account: LAccount) {}
118
-
119
- @Get("")
120
- getNews(@AccountId() accountId: string) {}
121
-
122
- @Perms("perms.get", "perms.list")
123
- @Get("")
124
- getNews(@AccountId() accountId: string, @AccountPerms() accountPerms: string[]) {}
125
- }
126
- ```
127
-
128
- ### Configuration
129
-
130
- To configure the underlying service instance, pass an optional options object to the `register()` method of `InternalModule` when importing it. This options object will be passed directly to the underlying service constructor.
131
-
132
- ```typescript
133
- @Module({
134
- imports: [
135
- InternalModule.register({
136
- target: Targets.NEWSROOM,
137
- token: 'itlab token',
138
- jwt_secret: 'secret',
139
- }),
140
- ],
141
- providers: [NewsService],
142
- })
143
- export class NewsModule {}
144
- ```
145
-
146
- ### Async configuration
147
-
148
- When you need to pass module options asynchronously instead of statically, use the `registerAsync()` method. As with most dynamic modules, this package provides several techniques to deal with async configuration.
149
-
150
- One technique is to use a factory function:
151
-
152
- ```typescript
153
- InternalModule.registerAsync({
154
- useFactory: () => ({
155
- target: Targets.NEWSROOM,
156
- token: 'itlab token',
157
- jwt_secret: 'secret',
158
- }),
159
- });
160
- ```
161
-
162
- Like other factory providers, our factory function can be [async](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory) and can inject dependencies through `inject`.
163
-
164
- ```typescript
165
- InternalModule.registerAsync({
166
- imports: [ConfigModule],
167
- useFactory: (configService: ConfigService) => ({
168
- target: Targets.NEWSROOM,
169
- token: configService.get<string>('K8S_TOKEN'),
170
- jwt_secret: configService.get<string>('JWT_SECRET'),
171
- }),
172
- inject: [ConfigService],
173
- });
174
- ```
175
-
176
- Alternatively, you can configure the `InternalModule` using a class instead of a factory, as shown below.
177
-
178
- ```typescript
179
- InternalModule.registerAsync({
180
- useClass: InternalConfigService,
181
- });
182
- ```
183
-
184
- The construction above instantiates `InternalConfigService` inside `InternalModule`, using it to create an options object. Note that in this example, the `InternalConfigService` has to implement `InternalModuleOptionsFactory` interface as shown below. The `InternalModule` will call the `createInternalOptions()` method on the instantiated object of the supplied class.
185
-
186
- ```typescript
187
- @Injectable()
188
- class InternalConfigService implements InternalModuleOptionsFactory {
189
- createInternalOptions(): InternalModuleOptions {
190
- return {
191
- target: Targets.NEWSROOM,
192
- token: 'itlab token',
193
- jwt_secret: 'secret',
194
- };
195
- }
196
- }
197
- ```
198
-
199
- If you want to reuse an existing options provider instead of creating a private copy inside the `InternalModule`, use the `useExisting` syntax.
200
-
201
- ```typescript
202
- InternalModule.registerAsync({
203
- imports: [ConfigModule],
204
- useExisting: InternalConfigService,
205
- });
206
- ```
@@ -51,8 +51,7 @@ class DocumentMerger {
51
51
  async merge(transform) {
52
52
  const startTime = Date.now();
53
53
  const cursor = this.model.find().cursor();
54
- // Process documents one by one to handle large collections efficiently
55
- for (let doc = await cursor.next(); doc != null; doc = await cursor.next()) {
54
+ await cursor.eachAsync(async (doc) => {
56
55
  // Apply user-defined transformation if provided
57
56
  if (transform) {
58
57
  doc = transform(doc);
@@ -74,7 +73,7 @@ class DocumentMerger {
74
73
  }
75
74
  // Save changes to the database without updating timestamps
76
75
  await doc.save({ timestamps: false });
77
- }
76
+ });
78
77
  const elapsedTime = Date.now() - startTime;
79
78
  // Log completion with fields merged and time taken
80
79
  this.logger.log(`Successfully merged fields: ${(0, itlab_functions_1.formatList)(this.fields)} (took ${elapsedTime} ms)`);
@@ -1,2 +1,5 @@
1
1
  export { DocumentMerger } from './document-merger.class';
2
- export { DocumentUpdater } from './document-updater.class';
2
+ export { ReportCategory } from './report-category.class';
3
+ export { SchemaBuilder } from './schema-builder.class';
4
+ export type { SchemaBuilderDocument, SchemaBuilderModel, SchemaBuilderOptions } from './schema-builder.class';
5
+ export { TaskManager } from './task-manager.class';
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentUpdater = exports.DocumentMerger = void 0;
3
+ exports.TaskManager = exports.SchemaBuilder = exports.ReportCategory = exports.DocumentMerger = void 0;
4
4
  var document_merger_class_1 = require("./document-merger.class");
5
5
  Object.defineProperty(exports, "DocumentMerger", { enumerable: true, get: function () { return document_merger_class_1.DocumentMerger; } });
6
- var document_updater_class_1 = require("./document-updater.class");
7
- Object.defineProperty(exports, "DocumentUpdater", { enumerable: true, get: function () { return document_updater_class_1.DocumentUpdater; } });
6
+ var report_category_class_1 = require("./report-category.class");
7
+ Object.defineProperty(exports, "ReportCategory", { enumerable: true, get: function () { return report_category_class_1.ReportCategory; } });
8
+ var schema_builder_class_1 = require("./schema-builder.class");
9
+ Object.defineProperty(exports, "SchemaBuilder", { enumerable: true, get: function () { return schema_builder_class_1.SchemaBuilder; } });
10
+ var task_manager_class_1 = require("./task-manager.class");
11
+ Object.defineProperty(exports, "TaskManager", { enumerable: true, get: function () { return task_manager_class_1.TaskManager; } });
@@ -0,0 +1,55 @@
1
+ import { Document } from 'mongoose';
2
+ /**
3
+ * Defines which array-type attributes of a document should be tracked,
4
+ * along with human-readable labels for reporting.
5
+ *
6
+ * Only attributes of type `string[]` are tracked.
7
+ *
8
+ * Example:
9
+ * { genres: "Genres", tags: "Tags" }
10
+ */
11
+ type ReportCategoryAttributes<T extends Document> = Partial<{
12
+ [K in keyof Omit<T, keyof Document> as T[K] extends string[] ? K : never]: string;
13
+ }>;
14
+ type ReportCategoryExport = Array<{
15
+ id: string;
16
+ } & Record<string, number>>;
17
+ /**
18
+ * ReportCategory
19
+ *
20
+ * Manages multiple AttributeAggregator instances, each associated
21
+ * with a unique entity key (e.g., organization, category).
22
+ * Provides methods to insert documents and export aggregated reports.
23
+ *
24
+ * @template T - A Mongoose document type with array attributes to track.
25
+ */
26
+ export declare class ReportCategory<T extends Document> {
27
+ private aggregators;
28
+ private attributes;
29
+ /**
30
+ * Initializes the report manager with the attributes to track.
31
+ *
32
+ * @param attributes - Mapping of document array attributes to display labels.
33
+ */
34
+ constructor(attributes: ReportCategoryAttributes<T>);
35
+ /**
36
+ * Inserts a document into one or multiple entity aggregators.
37
+ * Automatically creates the aggregator if it does not exist.
38
+ *
39
+ * @param document - The document to insert.
40
+ * @param entityKeys - Single or multiple entity identifiers.
41
+ */
42
+ insertDocument(document: T, entityKeys: string[] | string): void;
43
+ /**
44
+ * Exports aggregated statistics for all entities.
45
+ *
46
+ * Each object contains:
47
+ * - id: Entity key
48
+ * - documents: Number of documents processed for this entity
49
+ * - totalX / uniqueX: Aggregated counts for each tracked attribute
50
+ *
51
+ * @returns An array of aggregated reports for all entities.
52
+ */
53
+ export(): ReportCategoryExport;
54
+ }
55
+ export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReportCategory = void 0;
4
+ const itlab_functions_1 = require("itlab-functions");
5
+ /**
6
+ * AttributeAggregator
7
+ *
8
+ * Responsible for aggregating statistics for specified array attributes
9
+ * across multiple document records. Tracks both total counts and
10
+ * unique values for each attribute.
11
+ *
12
+ * @template T - A Mongoose document type with array attributes to track.
13
+ */
14
+ class AttributeAggregator {
15
+ /**
16
+ * Initializes the aggregator with the attributes to track.
17
+ *
18
+ * @param attributes - Mapping of document array attributes to display labels.
19
+ */
20
+ constructor(attributes) {
21
+ this.documents = 0;
22
+ this.totalCounts = new Map();
23
+ this.uniqueValues = new Map();
24
+ this.attributes = attributes;
25
+ }
26
+ /**
27
+ * Processes a single document, updating the total and unique value counts
28
+ * for each tracked attribute.
29
+ *
30
+ * @param document - The document to include in aggregation.
31
+ */
32
+ processDocument(document) {
33
+ this.documents++;
34
+ for (const attribute of Object.keys(this.attributes)) {
35
+ const values = document[attribute];
36
+ // Only handle array attributes
37
+ if (!Array.isArray(values))
38
+ continue;
39
+ // Update total count for this attribute
40
+ const previousTotal = this.totalCounts.get(attribute) || 0;
41
+ this.totalCounts.set(attribute, previousTotal + values.length);
42
+ // Update the set of unique values for this attribute
43
+ const currentUnique = this.uniqueValues.get(attribute) || new Set();
44
+ values.forEach((value) => currentUnique.add(String(value)));
45
+ this.uniqueValues.set(attribute, currentUnique);
46
+ }
47
+ }
48
+ /**
49
+ * Exports aggregated statistics for this aggregator.
50
+ *
51
+ * Returns an object containing:
52
+ * - documents: Number of documents processed
53
+ * - totalX: Total count of values for each attribute
54
+ * - uniqueX: Count of unique values for each attribute
55
+ *
56
+ * @returns An object representing the aggregated data.
57
+ */
58
+ export() {
59
+ var _a;
60
+ const report = {};
61
+ for (const [attribute, label] of Object.entries(this.attributes)) {
62
+ const capitalizedLabel = (0, itlab_functions_1.capitalize)(label);
63
+ report[`total${capitalizedLabel}`] = this.totalCounts.get(attribute) || 0;
64
+ report[`unique${capitalizedLabel}`] = ((_a = this.uniqueValues.get(attribute)) === null || _a === void 0 ? void 0 : _a.size) || 0;
65
+ }
66
+ return Object.assign({ documents: this.documents }, report);
67
+ }
68
+ }
69
+ /**
70
+ * ReportCategory
71
+ *
72
+ * Manages multiple AttributeAggregator instances, each associated
73
+ * with a unique entity key (e.g., organization, category).
74
+ * Provides methods to insert documents and export aggregated reports.
75
+ *
76
+ * @template T - A Mongoose document type with array attributes to track.
77
+ */
78
+ class ReportCategory {
79
+ /**
80
+ * Initializes the report manager with the attributes to track.
81
+ *
82
+ * @param attributes - Mapping of document array attributes to display labels.
83
+ */
84
+ constructor(attributes) {
85
+ this.aggregators = new Map();
86
+ this.attributes = attributes;
87
+ }
88
+ /**
89
+ * Inserts a document into one or multiple entity aggregators.
90
+ * Automatically creates the aggregator if it does not exist.
91
+ *
92
+ * @param document - The document to insert.
93
+ * @param entityKeys - Single or multiple entity identifiers.
94
+ */
95
+ insertDocument(document, entityKeys) {
96
+ var _a;
97
+ const keys = Array.isArray(entityKeys) ? entityKeys : [entityKeys];
98
+ for (const key of keys) {
99
+ const aggregator = (_a = this.aggregators.get(key)) !== null && _a !== void 0 ? _a : new AttributeAggregator(this.attributes);
100
+ aggregator.processDocument(document);
101
+ this.aggregators.set(key, aggregator);
102
+ }
103
+ }
104
+ /**
105
+ * Exports aggregated statistics for all entities.
106
+ *
107
+ * Each object contains:
108
+ * - id: Entity key
109
+ * - documents: Number of documents processed for this entity
110
+ * - totalX / uniqueX: Aggregated counts for each tracked attribute
111
+ *
112
+ * @returns An array of aggregated reports for all entities.
113
+ */
114
+ export() {
115
+ return Array.from(this.aggregators.entries()).map(([id, aggregator]) => {
116
+ return Object.assign({ id }, aggregator.export());
117
+ });
118
+ }
119
+ }
120
+ exports.ReportCategory = ReportCategory;
@@ -0,0 +1,75 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { Document, Model, Schema } from 'mongoose';
3
+ import { Likeable, Viewable } from '../types';
4
+ /**
5
+ * Options that determine how the schema should be extended.
6
+ *
7
+ * @template TClass - The document type for the schema.
8
+ */
9
+ export type SchemaBuilderOptions<TClass extends Document> = {
10
+ /** Whether this schema should support view tracking. */
11
+ viewable?: boolean;
12
+ /** Whether this schema should support like tracking. */
13
+ likeable?: boolean;
14
+ /**
15
+ * A set of keys that uniquely identify the document.
16
+ * These keys are used when checking for duplicates.
17
+ */
18
+ criticalKeys?: (keyof Omit<TClass, keyof Document>)[];
19
+ };
20
+ /**
21
+ * Computes the augmented document type based on SchemaOptions.
22
+ */
23
+ export type SchemaBuilderDocument<TClass extends Document, TOptions extends SchemaBuilderOptions<TClass>> = TClass & (TOptions['viewable'] extends true ? Viewable : object) & (TOptions['likeable'] extends true ? Likeable : object);
24
+ /**
25
+ * Extends a standard Mongoose model with custom static methods
26
+ * injected by the SchemaBuilder.
27
+ */
28
+ export type SchemaBuilderModel<TClass extends Document> = Model<TClass> & {
29
+ /**
30
+ * Checks if the given object is a duplicate of an existing document.
31
+ *
32
+ * @param dto - Partial object with properties to check for duplicates.
33
+ * @param updateTarget - The document being updated, if applicable.
34
+ * @returns {Promise<boolean>} - True if a duplicate exists, false otherwise.
35
+ */
36
+ isDuplicate(dto: Partial<TClass>, updateTarget?: TClass): Promise<boolean>;
37
+ };
38
+ /**
39
+ * Generic builder for creating extended Mongoose schemas.
40
+ *
41
+ * This class wraps Nest's SchemaFactory and automatically injects common
42
+ * behaviors such as:
43
+ * - View tracking (who viewed, view counts)
44
+ * - Like tracking (who liked, like counts)
45
+ * - Duplicate checking based on critical keys
46
+ *
47
+ * @template TClass - A class extending Mongoose Document.
48
+ */
49
+ export declare class SchemaBuilder<TClass extends Document> {
50
+ private schema;
51
+ readonly options: SchemaBuilderOptions<TClass>;
52
+ constructor(target: Type<TClass>, options?: SchemaBuilderOptions<TClass>);
53
+ /**
54
+ * Adds interaction tracking (likes or views) to a schema.
55
+ * This method generalizes the shared logic between "viewable" and "likeable".
56
+ *
57
+ * @param field - The internal array field storing account IDs. (e.g. _viewedBy or _likedBy)
58
+ * @param counter - The numeric counter field tracking totals. (e.g. views or likes)
59
+ */
60
+ provideInteraction(field: string, counter: string): this;
61
+ /**
62
+ * Adds a duplicate-checking static method to the schema.
63
+ * This method compares critical keys to detect conflicts.
64
+ */
65
+ private provideDuplicateChecker;
66
+ /**
67
+ * Finalizes the schema and injects any selected behaviors (viewable, likeable, duplicate checking).
68
+ *
69
+ * @returns An object containing:
70
+ * - `schema`: The Mongoose schema.
71
+ * - `modelType`: A strongly typed model with additional static methods.
72
+ * - `documentType`: The inferred document type with injected properties.
73
+ */
74
+ build(): Schema;
75
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaBuilder = void 0;
4
+ const mongoose_1 = require("@nestjs/mongoose");
5
+ const class_validator_1 = require("class-validator");
6
+ /**
7
+ * Generic builder for creating extended Mongoose schemas.
8
+ *
9
+ * This class wraps Nest's SchemaFactory and automatically injects common
10
+ * behaviors such as:
11
+ * - View tracking (who viewed, view counts)
12
+ * - Like tracking (who liked, like counts)
13
+ * - Duplicate checking based on critical keys
14
+ *
15
+ * @template TClass - A class extending Mongoose Document.
16
+ */
17
+ class SchemaBuilder {
18
+ constructor(target, options = {}) {
19
+ this.schema = mongoose_1.SchemaFactory.createForClass(target);
20
+ this.options = options;
21
+ /**
22
+ * Create a wildcard index required for CosmosDB to support sorting on all fields.
23
+ *
24
+ * This is a workaround for CosmosDB's partial MongoDB API compatibility.
25
+ * See: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/indexing#wildcard-indexes
26
+ */
27
+ this.schema.index({ '$**': 1 }, { name: 'Sort Index' });
28
+ this.provideDuplicateChecker();
29
+ }
30
+ /**
31
+ * Adds interaction tracking (likes or views) to a schema.
32
+ * This method generalizes the shared logic between "viewable" and "likeable".
33
+ *
34
+ * @param field - The internal array field storing account IDs. (e.g. _viewedBy or _likedBy)
35
+ * @param counter - The numeric counter field tracking totals. (e.g. views or likes)
36
+ */
37
+ provideInteraction(field, counter) {
38
+ // Add fields to the schema
39
+ this.schema.add({ [field]: { type: [String], default: [] }, [counter]: { type: Number, default: 0 } });
40
+ // Expose a virtual property (without underscore) for convenience
41
+ this.schema.virtual(field.replace(/^_/, ''));
42
+ // Add method to increment counter
43
+ this.schema.methods[`add${counter[0].toUpperCase() + counter.slice(1)}`] = async function (accountId) {
44
+ if (!(0, class_validator_1.isMongoId)(accountId))
45
+ return Number(this[counter]);
46
+ // Ensure uniqueness by converting to a Set
47
+ this[field] = Array.from(new Set([...this[field], accountId]));
48
+ this[counter] = this[field].length;
49
+ await this.save({ timestamps: false });
50
+ return this[counter];
51
+ };
52
+ // Add method to decrement counter
53
+ this.schema.methods[`remove${counter[0].toUpperCase() + counter.slice(1)}`] = async function (accountId) {
54
+ if (!(0, class_validator_1.isMongoId)(accountId))
55
+ return Number(this[counter]);
56
+ // Remove the accountId from the list
57
+ this[field] = this[field].filter((id) => id !== accountId);
58
+ this[counter] = this[field].length;
59
+ await this.save({ timestamps: false });
60
+ return this[counter];
61
+ };
62
+ return this;
63
+ }
64
+ /**
65
+ * Adds a duplicate-checking static method to the schema.
66
+ * This method compares critical keys to detect conflicts.
67
+ */
68
+ provideDuplicateChecker() {
69
+ var _a;
70
+ const criticalKeys = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.criticalKeys) || [];
71
+ this.schema.statics.isDuplicate = async function (dto, updateTarget) {
72
+ var _a;
73
+ if (criticalKeys.length === 0)
74
+ return false;
75
+ // Build a filter using the critical keys
76
+ const filterQuery = criticalKeys.reduce((query, key) => {
77
+ if (dto && key in dto)
78
+ query[String(key)] = dto[key];
79
+ else if (updateTarget && key in updateTarget)
80
+ query[String(key)] = updateTarget[key];
81
+ return query;
82
+ }, {});
83
+ // If a matching document exists, check whether it’s the same entity
84
+ const potentialDuplicate = await this.findOne(filterQuery);
85
+ if (!potentialDuplicate)
86
+ return false;
87
+ const potentialId = potentialDuplicate._id.toString().toLowerCase();
88
+ const targetId = (_a = updateTarget === null || updateTarget === void 0 ? void 0 : updateTarget._id) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
89
+ return potentialId !== targetId;
90
+ };
91
+ }
92
+ /**
93
+ * Finalizes the schema and injects any selected behaviors (viewable, likeable, duplicate checking).
94
+ *
95
+ * @returns An object containing:
96
+ * - `schema`: The Mongoose schema.
97
+ * - `modelType`: A strongly typed model with additional static methods.
98
+ * - `documentType`: The inferred document type with injected properties.
99
+ */
100
+ build() {
101
+ var _a, _b;
102
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.viewable)
103
+ this.provideInteraction('_viewedBy', 'views');
104
+ if ((_b = this.options) === null || _b === void 0 ? void 0 : _b.likeable)
105
+ this.provideInteraction('_likedBy', 'likes');
106
+ return this.schema;
107
+ }
108
+ }
109
+ exports.SchemaBuilder = SchemaBuilder;
@@ -0,0 +1,71 @@
1
+ import { Account, User } from '../models';
2
+ import { AccountsService } from '../modules';
3
+ /**
4
+ * TaskManager is a utility class that collects asynchronous tasks
5
+ * and executes them in parallel.
6
+ *
7
+ * This is especially useful for orchestrating optional async operations
8
+ * where not all tasks need to be executed every time.
9
+ *
10
+ * Example:
11
+ * ```ts
12
+ * const taskManager = new TaskManager();
13
+ * taskManager.add(async () => { ... });
14
+ * taskManager.add(async () => { ... });
15
+ * await taskManager.run();
16
+ * ```
17
+ */
18
+ export declare class TaskManager {
19
+ private tasks;
20
+ /**
21
+ * Fetches all users for the given ID groups and returns a mapping.
22
+ * Ensures each user is fetched only once.
23
+ * @param userIdGroups Array of arrays of user IDs (e.g., authors, likedBy, viewedBy)
24
+ * @param accountsService Service responsible for fetching users
25
+ * @returns Map of userId -> user
26
+ */
27
+ static fetchAndMapUsers(userIdGroups: string[][], accountsService: AccountsService): Promise<Map<string, User>>;
28
+ /**
29
+ * Fetches all users for the given ID groups and returns a mapping.
30
+ * Ensures each user is fetched only once.
31
+ * @param accountIdGroups Array of arrays of user IDs (e.g., authors, likedBy, viewedBy)
32
+ * @param accountsService Service responsible for fetching users
33
+ * @returns Map of userId -> user
34
+ */
35
+ static fetchAndMapAccounts(accountIdGroups: string[][], accountsService: AccountsService): Promise<Map<string, Account>>;
36
+ /**
37
+ * Maps an array of IDs to user objects using a userMap.
38
+ * Filters out any IDs that don’t have a corresponding user.
39
+ * @param userIds Array of user IDs to map
40
+ * @param userMap Map of userId -> user object
41
+ * @returns Array of user objects
42
+ */
43
+ static mapIdsToUsers(userIds: string[], userMap: Map<string, User>): any[];
44
+ /**
45
+ * Maps an array of IDs to user objects using a userMap.
46
+ * Filters out any IDs that don’t have a corresponding user.
47
+ * @param accountIds Array of user IDs to map
48
+ * @param accountMap Map of userId -> user object
49
+ * @returns Array of user objects
50
+ */
51
+ static mapIdsToAccounts(accountIds: string[], accountMap: Map<string, Account>): any[];
52
+ /**
53
+ * Adds a new asynchronous task to the queue.
54
+ *
55
+ * @param task - A function that returns a Promise.
56
+ * It should contain the actual async logic to be executed.
57
+ */
58
+ add(task: () => Promise<void>): void;
59
+ /**
60
+ * Executes all queued tasks in parallel and waits for their completion.
61
+ *
62
+ * - Tasks are executed concurrently using `Promise.all`.
63
+ * - If one task fails, the error will propagate and stop execution.
64
+ */
65
+ run(): Promise<void>;
66
+ /**
67
+ * Clears all tasks from the queue without executing them.
68
+ * Useful if you want to reset and reuse the TaskManager instance.
69
+ */
70
+ clear(): void;
71
+ }