@lyxa.ai/marketing 1.0.48 → 1.0.50

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 (324) hide show
  1. package/dist/lib/event/event-initializations.js +2 -2
  2. package/dist/lib/event/event-initializations.js.map +1 -1
  3. package/dist/lib/index.d.ts +462 -508
  4. package/dist/lib/index.d.ts.map +1 -1
  5. package/dist/lib/modules/coupon/services/coupon.service.d.ts +2 -2
  6. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  7. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  8. package/dist/lib/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
  9. package/dist/lib/modules/coupon/services/global-coupon.service.js +2 -0
  10. package/dist/lib/modules/coupon/services/global-coupon.service.js.map +1 -1
  11. package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -1
  12. package/dist/lib/modules/coupon/services/helper.service.js +2 -0
  13. package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
  14. package/dist/lib/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
  15. package/dist/lib/modules/coupon/services/individual-user-coupon.service.js +2 -0
  16. package/dist/lib/modules/coupon/services/individual-user-coupon.service.js.map +1 -1
  17. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  18. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +2 -0
  19. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
  20. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +10 -21
  21. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  22. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +5 -4
  23. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
  24. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +154 -0
  25. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  26. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +13 -1
  27. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
  28. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +8 -2
  29. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  30. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +11 -2
  31. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
  32. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -21
  33. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  34. package/dist/lib/modules/tournament/config/config.builder.d.ts.map +1 -1
  35. package/dist/lib/modules/tournament/config/config.builder.js +4 -0
  36. package/dist/lib/modules/tournament/config/config.builder.js.map +1 -1
  37. package/dist/lib/modules/tournament/config/config.repository.d.ts +4 -0
  38. package/dist/lib/modules/tournament/config/config.repository.d.ts.map +1 -1
  39. package/dist/lib/modules/tournament/config/config.repository.js +10 -1
  40. package/dist/lib/modules/tournament/config/config.repository.js.map +1 -1
  41. package/dist/lib/modules/tournament/config/config.router.d.ts +106 -218
  42. package/dist/lib/modules/tournament/config/config.router.d.ts.map +1 -1
  43. package/dist/lib/modules/tournament/config/config.service.d.ts +2 -2
  44. package/dist/lib/modules/tournament/config/config.service.d.ts.map +1 -1
  45. package/dist/lib/modules/tournament/config/config.service.js.map +1 -1
  46. package/dist/lib/modules/tournament/config/config.validation.d.ts +446 -692
  47. package/dist/lib/modules/tournament/config/config.validation.d.ts.map +1 -1
  48. package/dist/lib/modules/tournament/config/config.validation.js +44 -28
  49. package/dist/lib/modules/tournament/config/config.validation.js.map +1 -1
  50. package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.d.ts +2 -0
  51. package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.d.ts.map +1 -0
  52. package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.js +28 -0
  53. package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.js.map +1 -0
  54. package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.d.ts +15 -0
  55. package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.d.ts.map +1 -0
  56. package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.js +12 -0
  57. package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.js.map +1 -0
  58. package/dist/lib/modules/tournament/match/match.builder.d.ts +5 -2
  59. package/dist/lib/modules/tournament/match/match.builder.d.ts.map +1 -1
  60. package/dist/lib/modules/tournament/match/match.builder.js +13 -7
  61. package/dist/lib/modules/tournament/match/match.builder.js.map +1 -1
  62. package/dist/lib/modules/tournament/match/match.repository.d.ts +2 -0
  63. package/dist/lib/modules/tournament/match/match.repository.d.ts.map +1 -1
  64. package/dist/lib/modules/tournament/match/match.repository.js +10 -0
  65. package/dist/lib/modules/tournament/match/match.repository.js.map +1 -1
  66. package/dist/lib/modules/tournament/match/match.router.d.ts +66 -191
  67. package/dist/lib/modules/tournament/match/match.router.d.ts.map +1 -1
  68. package/dist/lib/modules/tournament/match/match.router.js +0 -7
  69. package/dist/lib/modules/tournament/match/match.router.js.map +1 -1
  70. package/dist/lib/modules/tournament/match/match.service.d.ts +1 -12
  71. package/dist/lib/modules/tournament/match/match.service.d.ts.map +1 -1
  72. package/dist/lib/modules/tournament/match/match.service.js +18 -68
  73. package/dist/lib/modules/tournament/match/match.service.js.map +1 -1
  74. package/dist/lib/modules/tournament/match/match.validation.d.ts +96 -34
  75. package/dist/lib/modules/tournament/match/match.validation.d.ts.map +1 -1
  76. package/dist/lib/modules/tournament/match/match.validation.js +5 -2
  77. package/dist/lib/modules/tournament/match/match.validation.js.map +1 -1
  78. package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts +2 -5
  79. package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -1
  80. package/dist/lib/modules/tournament/notification/jobs/notification.producer.js +1 -6
  81. package/dist/lib/modules/tournament/notification/jobs/notification.producer.js.map +1 -1
  82. package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts +2 -0
  83. package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -1
  84. package/dist/lib/modules/tournament/notification/jobs/notification.worker.js +15 -9
  85. package/dist/lib/modules/tournament/notification/jobs/notification.worker.js.map +1 -1
  86. package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts +8 -0
  87. package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts.map +1 -0
  88. package/dist/lib/modules/tournament/notification/notification-template.repository.js +60 -0
  89. package/dist/lib/modules/tournament/notification/notification-template.repository.js.map +1 -0
  90. package/dist/lib/modules/tournament/notification/notification.config.d.ts +10 -0
  91. package/dist/lib/modules/tournament/notification/notification.config.d.ts.map +1 -0
  92. package/dist/lib/modules/tournament/notification/notification.config.js +15 -0
  93. package/dist/lib/modules/tournament/notification/notification.config.js.map +1 -0
  94. package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts +10 -0
  95. package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts.map +1 -0
  96. package/dist/lib/modules/tournament/notification/notification.schedule.config.js +15 -0
  97. package/dist/lib/modules/tournament/notification/notification.schedule.config.js.map +1 -0
  98. package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts +4 -4
  99. package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -1
  100. package/dist/lib/modules/tournament/notification/notification.scheduler.service.js +15 -28
  101. package/dist/lib/modules/tournament/notification/notification.scheduler.service.js.map +1 -1
  102. package/dist/lib/modules/tournament/notification/notification.service.d.ts +5 -3
  103. package/dist/lib/modules/tournament/notification/notification.service.d.ts.map +1 -1
  104. package/dist/lib/modules/tournament/notification/notification.service.js +33 -23
  105. package/dist/lib/modules/tournament/notification/notification.service.js.map +1 -1
  106. package/dist/lib/modules/tournament/participant/participant.repository.d.ts +1 -0
  107. package/dist/lib/modules/tournament/participant/participant.repository.d.ts.map +1 -1
  108. package/dist/lib/modules/tournament/participant/participant.repository.js +6 -0
  109. package/dist/lib/modules/tournament/participant/participant.repository.js.map +1 -1
  110. package/dist/lib/modules/tournament/participant/participant.router.d.ts +9 -9
  111. package/dist/lib/modules/tournament/participant/participant.validation.d.ts +84 -84
  112. package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
  113. package/dist/lib/modules/tournament/prediction/prediction.builder.js +3 -2
  114. package/dist/lib/modules/tournament/prediction/prediction.builder.js.map +1 -1
  115. package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts +4 -1
  116. package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts.map +1 -1
  117. package/dist/lib/modules/tournament/prediction/prediction.repository.js +20 -2
  118. package/dist/lib/modules/tournament/prediction/prediction.repository.js.map +1 -1
  119. package/dist/lib/modules/tournament/prediction/prediction.router.d.ts +12 -12
  120. package/dist/lib/modules/tournament/prediction/prediction.service.d.ts +9 -0
  121. package/dist/lib/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
  122. package/dist/lib/modules/tournament/prediction/prediction.service.js +30 -4
  123. package/dist/lib/modules/tournament/prediction/prediction.service.js.map +1 -1
  124. package/dist/lib/modules/tournament/prediction/prediction.validation.d.ts +64 -64
  125. package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +3 -0
  126. package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -1
  127. package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js +21 -5
  128. package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js.map +1 -1
  129. package/dist/lib/modules/tournament/reward/reward.builder.d.ts +6 -0
  130. package/dist/lib/modules/tournament/reward/reward.builder.d.ts.map +1 -0
  131. package/dist/lib/modules/tournament/reward/reward.builder.js +44 -0
  132. package/dist/lib/modules/tournament/reward/reward.builder.js.map +1 -0
  133. package/dist/lib/modules/tournament/reward/reward.interface.d.ts.map +1 -1
  134. package/dist/lib/modules/tournament/reward/reward.interface.js.map +1 -1
  135. package/dist/lib/modules/tournament/reward/reward.repository.d.ts +8 -0
  136. package/dist/lib/modules/tournament/reward/reward.repository.d.ts.map +1 -0
  137. package/dist/lib/modules/tournament/reward/reward.repository.js +66 -0
  138. package/dist/lib/modules/tournament/reward/reward.repository.js.map +1 -0
  139. package/dist/lib/modules/tournament/reward/reward.service.d.ts.map +1 -1
  140. package/dist/lib/modules/tournament/reward/reward.service.js.map +1 -1
  141. package/dist/lib/modules/tournament/reward/reward.types.d.ts +1 -1
  142. package/dist/lib/modules/tournament/reward/reward.types.d.ts.map +1 -1
  143. package/dist/lib/modules/tournament/reward/reward.types.js.map +1 -1
  144. package/dist/lib/modules/tournament/schedule/schedule.router.d.ts +27 -0
  145. package/dist/lib/modules/tournament/schedule/schedule.router.d.ts.map +1 -0
  146. package/dist/lib/modules/tournament/schedule/schedule.router.js +17 -0
  147. package/dist/lib/modules/tournament/schedule/schedule.router.js.map +1 -0
  148. package/dist/lib/modules/tournament/schedule/schedule.service.d.ts +10 -0
  149. package/dist/lib/modules/tournament/schedule/schedule.service.d.ts.map +1 -0
  150. package/dist/lib/modules/tournament/schedule/schedule.service.js +87 -0
  151. package/dist/lib/modules/tournament/schedule/schedule.service.js.map +1 -0
  152. package/dist/lib/modules/tournament/score/score.repository.d.ts +13 -0
  153. package/dist/lib/modules/tournament/score/score.repository.d.ts.map +1 -0
  154. package/dist/lib/modules/tournament/score/score.repository.js +70 -0
  155. package/dist/lib/modules/tournament/score/score.repository.js.map +1 -0
  156. package/dist/lib/modules/tournament/score/score.router.d.ts +98 -0
  157. package/dist/lib/modules/tournament/score/score.router.d.ts.map +1 -0
  158. package/dist/lib/modules/tournament/score/score.router.js +20 -0
  159. package/dist/lib/modules/tournament/score/score.router.js.map +1 -0
  160. package/dist/lib/modules/tournament/score/score.service.d.ts +13 -0
  161. package/dist/lib/modules/tournament/score/score.service.d.ts.map +1 -0
  162. package/dist/lib/modules/tournament/score/score.service.js +109 -0
  163. package/dist/lib/modules/tournament/score/score.service.js.map +1 -0
  164. package/dist/lib/modules/tournament/score/score.validation.d.ts +375 -0
  165. package/dist/lib/modules/tournament/score/score.validation.d.ts.map +1 -0
  166. package/dist/lib/modules/tournament/score/score.validation.js +19 -0
  167. package/dist/lib/modules/tournament/score/score.validation.js.map +1 -0
  168. package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts +10 -0
  169. package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts.map +1 -0
  170. package/dist/lib/modules/tournament/statistics/statistics.builder.js +53 -0
  171. package/dist/lib/modules/tournament/statistics/statistics.builder.js.map +1 -0
  172. package/dist/lib/modules/tournament/statistics/statistics.router.d.ts +80 -0
  173. package/dist/lib/modules/tournament/statistics/statistics.router.d.ts.map +1 -0
  174. package/dist/lib/modules/tournament/statistics/statistics.router.js +21 -0
  175. package/dist/lib/modules/tournament/statistics/statistics.router.js.map +1 -0
  176. package/dist/lib/modules/tournament/statistics/statistics.service.d.ts +11 -0
  177. package/dist/lib/modules/tournament/statistics/statistics.service.d.ts.map +1 -0
  178. package/dist/lib/modules/tournament/statistics/statistics.service.js +80 -0
  179. package/dist/lib/modules/tournament/statistics/statistics.service.js.map +1 -0
  180. package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts +404 -0
  181. package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts.map +1 -0
  182. package/dist/lib/modules/tournament/statistics/statistics.validation.js +36 -0
  183. package/dist/lib/modules/tournament/statistics/statistics.validation.js.map +1 -0
  184. package/dist/lib/modules/tournament/team/team.router.d.ts +31 -57
  185. package/dist/lib/modules/tournament/team/team.router.d.ts.map +1 -1
  186. package/dist/lib/modules/tournament/team/team.service.d.ts +1 -0
  187. package/dist/lib/modules/tournament/team/team.service.d.ts.map +1 -1
  188. package/dist/lib/modules/tournament/team/team.service.js +21 -16
  189. package/dist/lib/modules/tournament/team/team.service.js.map +1 -1
  190. package/dist/lib/modules/tournament/team/team.validation.d.ts +68 -18
  191. package/dist/lib/modules/tournament/team/team.validation.d.ts.map +1 -1
  192. package/dist/lib/modules/tournament/team/team.validation.js +4 -2
  193. package/dist/lib/modules/tournament/team/team.validation.js.map +1 -1
  194. package/dist/lib/modules/tournament/tournament.router.d.ts +466 -501
  195. package/dist/lib/modules/tournament/tournament.router.d.ts.map +1 -1
  196. package/dist/lib/modules/tournament/tournament.router.js +14 -0
  197. package/dist/lib/modules/tournament/tournament.router.js.map +1 -1
  198. package/dist/lib/modules/tournament/tournament.service.d.ts +8 -0
  199. package/dist/lib/modules/tournament/tournament.service.d.ts.map +1 -0
  200. package/dist/lib/modules/tournament/tournament.service.js +63 -0
  201. package/dist/lib/modules/tournament/tournament.service.js.map +1 -0
  202. package/dist/lib/modules/tournament/tournament.types.d.ts +9 -0
  203. package/dist/lib/modules/tournament/tournament.types.d.ts.map +1 -0
  204. package/dist/lib/modules/tournament/tournament.types.js +14 -0
  205. package/dist/lib/modules/tournament/tournament.types.js.map +1 -0
  206. package/dist/lib/modules/tournament/tournament.utils.d.ts +2 -0
  207. package/dist/lib/modules/tournament/tournament.utils.d.ts.map +1 -0
  208. package/dist/lib/modules/tournament/tournament.utils.js +6 -0
  209. package/dist/lib/modules/tournament/tournament.utils.js.map +1 -0
  210. package/dist/lib/modules/tournament/tournament.validation.d.ts +133 -0
  211. package/dist/lib/modules/tournament/tournament.validation.d.ts.map +1 -0
  212. package/dist/lib/modules/tournament/tournament.validation.js +14 -0
  213. package/dist/lib/modules/tournament/tournament.validation.js.map +1 -0
  214. package/dist/types/index.d.ts +462 -508
  215. package/dist/types/index.d.ts.map +1 -1
  216. package/dist/types/modules/coupon/services/coupon.service.d.ts +2 -2
  217. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  218. package/dist/types/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
  219. package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -1
  220. package/dist/types/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
  221. package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  222. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +10 -21
  223. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  224. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +154 -0
  225. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  226. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +8 -2
  227. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  228. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -21
  229. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  230. package/dist/types/modules/tournament/config/config.builder.d.ts.map +1 -1
  231. package/dist/types/modules/tournament/config/config.repository.d.ts +4 -0
  232. package/dist/types/modules/tournament/config/config.repository.d.ts.map +1 -1
  233. package/dist/types/modules/tournament/config/config.router.d.ts +106 -218
  234. package/dist/types/modules/tournament/config/config.router.d.ts.map +1 -1
  235. package/dist/types/modules/tournament/config/config.service.d.ts +2 -2
  236. package/dist/types/modules/tournament/config/config.service.d.ts.map +1 -1
  237. package/dist/types/modules/tournament/config/config.validation.d.ts +446 -692
  238. package/dist/types/modules/tournament/config/config.validation.d.ts.map +1 -1
  239. package/dist/types/modules/tournament/match/events/evaluate-predictions.consumer.d.ts +2 -0
  240. package/dist/types/modules/tournament/match/events/evaluate-predictions.consumer.d.ts.map +1 -0
  241. package/dist/types/modules/tournament/match/events/evaluate-predictions.event.d.ts +15 -0
  242. package/dist/types/modules/tournament/match/events/evaluate-predictions.event.d.ts.map +1 -0
  243. package/dist/types/modules/tournament/match/match.builder.d.ts +5 -2
  244. package/dist/types/modules/tournament/match/match.builder.d.ts.map +1 -1
  245. package/dist/types/modules/tournament/match/match.repository.d.ts +2 -0
  246. package/dist/types/modules/tournament/match/match.repository.d.ts.map +1 -1
  247. package/dist/types/modules/tournament/match/match.router.d.ts +66 -191
  248. package/dist/types/modules/tournament/match/match.router.d.ts.map +1 -1
  249. package/dist/types/modules/tournament/match/match.service.d.ts +1 -12
  250. package/dist/types/modules/tournament/match/match.service.d.ts.map +1 -1
  251. package/dist/types/modules/tournament/match/match.validation.d.ts +96 -34
  252. package/dist/types/modules/tournament/match/match.validation.d.ts.map +1 -1
  253. package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts +2 -5
  254. package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -1
  255. package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts +2 -0
  256. package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -1
  257. package/dist/types/modules/tournament/notification/notification-template.repository.d.ts +8 -0
  258. package/dist/types/modules/tournament/notification/notification-template.repository.d.ts.map +1 -0
  259. package/dist/types/modules/tournament/notification/notification.config.d.ts +10 -0
  260. package/dist/types/modules/tournament/notification/notification.config.d.ts.map +1 -0
  261. package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts +10 -0
  262. package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts.map +1 -0
  263. package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts +4 -4
  264. package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -1
  265. package/dist/types/modules/tournament/notification/notification.service.d.ts +5 -3
  266. package/dist/types/modules/tournament/notification/notification.service.d.ts.map +1 -1
  267. package/dist/types/modules/tournament/participant/participant.repository.d.ts +1 -0
  268. package/dist/types/modules/tournament/participant/participant.repository.d.ts.map +1 -1
  269. package/dist/types/modules/tournament/participant/participant.router.d.ts +9 -9
  270. package/dist/types/modules/tournament/participant/participant.validation.d.ts +84 -84
  271. package/dist/types/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
  272. package/dist/types/modules/tournament/prediction/prediction.repository.d.ts +4 -1
  273. package/dist/types/modules/tournament/prediction/prediction.repository.d.ts.map +1 -1
  274. package/dist/types/modules/tournament/prediction/prediction.router.d.ts +12 -12
  275. package/dist/types/modules/tournament/prediction/prediction.service.d.ts +9 -0
  276. package/dist/types/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
  277. package/dist/types/modules/tournament/prediction/prediction.validation.d.ts +64 -64
  278. package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +3 -0
  279. package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -1
  280. package/dist/types/modules/tournament/reward/reward.builder.d.ts +6 -0
  281. package/dist/types/modules/tournament/reward/reward.builder.d.ts.map +1 -0
  282. package/dist/types/modules/tournament/reward/reward.interface.d.ts.map +1 -1
  283. package/dist/types/modules/tournament/reward/reward.repository.d.ts +8 -0
  284. package/dist/types/modules/tournament/reward/reward.repository.d.ts.map +1 -0
  285. package/dist/types/modules/tournament/reward/reward.service.d.ts.map +1 -1
  286. package/dist/types/modules/tournament/reward/reward.types.d.ts +1 -1
  287. package/dist/types/modules/tournament/reward/reward.types.d.ts.map +1 -1
  288. package/dist/types/modules/tournament/schedule/schedule.router.d.ts +27 -0
  289. package/dist/types/modules/tournament/schedule/schedule.router.d.ts.map +1 -0
  290. package/dist/types/modules/tournament/schedule/schedule.service.d.ts +10 -0
  291. package/dist/types/modules/tournament/schedule/schedule.service.d.ts.map +1 -0
  292. package/dist/types/modules/tournament/score/score.repository.d.ts +13 -0
  293. package/dist/types/modules/tournament/score/score.repository.d.ts.map +1 -0
  294. package/dist/types/modules/tournament/score/score.router.d.ts +98 -0
  295. package/dist/types/modules/tournament/score/score.router.d.ts.map +1 -0
  296. package/dist/types/modules/tournament/score/score.service.d.ts +13 -0
  297. package/dist/types/modules/tournament/score/score.service.d.ts.map +1 -0
  298. package/dist/types/modules/tournament/score/score.validation.d.ts +375 -0
  299. package/dist/types/modules/tournament/score/score.validation.d.ts.map +1 -0
  300. package/dist/types/modules/tournament/statistics/statistics.builder.d.ts +10 -0
  301. package/dist/types/modules/tournament/statistics/statistics.builder.d.ts.map +1 -0
  302. package/dist/types/modules/tournament/statistics/statistics.router.d.ts +80 -0
  303. package/dist/types/modules/tournament/statistics/statistics.router.d.ts.map +1 -0
  304. package/dist/types/modules/tournament/statistics/statistics.service.d.ts +11 -0
  305. package/dist/types/modules/tournament/statistics/statistics.service.d.ts.map +1 -0
  306. package/dist/types/modules/tournament/statistics/statistics.validation.d.ts +404 -0
  307. package/dist/types/modules/tournament/statistics/statistics.validation.d.ts.map +1 -0
  308. package/dist/types/modules/tournament/team/team.router.d.ts +31 -57
  309. package/dist/types/modules/tournament/team/team.router.d.ts.map +1 -1
  310. package/dist/types/modules/tournament/team/team.service.d.ts +1 -0
  311. package/dist/types/modules/tournament/team/team.service.d.ts.map +1 -1
  312. package/dist/types/modules/tournament/team/team.validation.d.ts +68 -18
  313. package/dist/types/modules/tournament/team/team.validation.d.ts.map +1 -1
  314. package/dist/types/modules/tournament/tournament.router.d.ts +466 -501
  315. package/dist/types/modules/tournament/tournament.router.d.ts.map +1 -1
  316. package/dist/types/modules/tournament/tournament.service.d.ts +8 -0
  317. package/dist/types/modules/tournament/tournament.service.d.ts.map +1 -0
  318. package/dist/types/modules/tournament/tournament.types.d.ts +9 -0
  319. package/dist/types/modules/tournament/tournament.types.d.ts.map +1 -0
  320. package/dist/types/modules/tournament/tournament.utils.d.ts +2 -0
  321. package/dist/types/modules/tournament/tournament.utils.d.ts.map +1 -0
  322. package/dist/types/modules/tournament/tournament.validation.d.ts +133 -0
  323. package/dist/types/modules/tournament/tournament.validation.d.ts.map +1 -0
  324. package/package.json +2 -2
@@ -44,33 +44,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.matchService = exports.MatchService = void 0;
46
46
  const typedi_1 = __importStar(require("typedi"));
47
- const server_1 = require("@trpc/server");
48
47
  const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
49
48
  const event_1 = require("@lyxa.ai/core/dist/libraries/event");
50
49
  const match_repository_1 = require("./match.repository");
51
50
  const match_builder_1 = require("./match.builder");
52
- const notification_scheduler_service_1 = require("../notification/notification.scheduler.service");
53
- const notification_service_1 = require("../notification/notification.service");
54
- const participant_service_1 = require("../participant/participant.service");
55
- const prediction_repository_1 = require("../prediction/prediction.repository");
56
- const reward_service_1 = require("../reward/reward.service");
57
- const reward_types_1 = require("../reward/reward.types");
58
- const match_ended_event_1 = require("./events/match-ended.event");
59
- const FWC_COUPON_CODE = 'FWC01';
51
+ const evaluate_predictions_event_1 = require("./events/evaluate-predictions.event");
52
+ const tournament_utils_1 = require("../tournament.utils");
60
53
  let MatchService = class MatchService {
61
54
  repository;
62
- notificationScheduler;
63
- notificationService;
64
- participantService;
65
- predictionRepository;
66
- rewardService;
67
55
  constructor() {
68
56
  this.repository = typedi_1.default.get(match_repository_1.TournamentMatchRepository);
69
- this.notificationScheduler = typedi_1.default.get(notification_scheduler_service_1.NotificationSchedulerService);
70
- this.notificationService = typedi_1.default.get(notification_service_1.TournamentNotificationService);
71
- this.participantService = typedi_1.default.get(participant_service_1.ParticipantService);
72
- this.predictionRepository = typedi_1.default.get(prediction_repository_1.PredictionRepository);
73
- this.rewardService = typedi_1.default.get(reward_service_1.RewardService);
74
57
  }
75
58
  async getTournament(tournamentId) {
76
59
  const tournament = await this.repository.findById(tournamentId);
@@ -84,13 +67,6 @@ let MatchService = class MatchService {
84
67
  throw (0, error_common_1.notFoundError)('Match not found');
85
68
  return match;
86
69
  }
87
- validateWinner(match, winnerId) {
88
- if (!winnerId)
89
- return;
90
- if (![match.team1.teamId.toString(), match.team2.teamId.toString()].includes(winnerId.toString())) {
91
- throw (0, error_common_1.badRequestError)('Winner must be one of the match teams');
92
- }
93
- }
94
70
  resolveMatchTeams(tournament, team1Id, team2Id) {
95
71
  const teamsById = new Map(tournament.teams.map(team => [team._id.toString(), team]));
96
72
  const team1 = teamsById.get(team1Id.toString());
@@ -99,36 +75,15 @@ let MatchService = class MatchService {
99
75
  throw (0, error_common_1.badRequestError)('All match teams must exist in the tournament');
100
76
  return { team1, team2 };
101
77
  }
102
- async applyMatchUpdate(tournamentId, matchId, updates, errorMessage) {
78
+ async applyMatchUpdate(tournamentId, matchId, updates) {
103
79
  const result = await this.repository.updateMatch(tournamentId, matchId, updates);
104
80
  if (!result)
105
- throw new server_1.TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: errorMessage });
81
+ throw (0, error_common_1.notFoundError)('Tournament not found');
106
82
  const updated = result.matches.find(m => m._id.toString() === matchId.toString());
107
83
  if (!updated)
108
84
  throw (0, error_common_1.notFoundError)('Match not found');
109
85
  return updated;
110
86
  }
111
- async handleMatchEnded(tournamentId, matchId, finalScore) {
112
- const participants = await this.participantService.getAll(tournamentId);
113
- await Promise.all(participants.map(async (participant) => {
114
- const prediction = participant.predictions.find(p => p.matchId.toString() === matchId.toString());
115
- if (!prediction)
116
- return;
117
- const correct = prediction.score.team1 === finalScore.team1 &&
118
- prediction.score.team2 === finalScore.team2;
119
- await this.predictionRepository.setSucceeded(participant._id, matchId, correct);
120
- if (correct) {
121
- const expiresAt = new Date();
122
- expiresAt.setMonth(expiresAt.getMonth() + 1);
123
- await this.rewardService.grant(reward_types_1.RewardType.COUPON, {
124
- userId: participant.userId,
125
- tournamentId,
126
- matchId,
127
- payload: { code: FWC_COUPON_CODE, expiresAt },
128
- });
129
- }
130
- }));
131
- }
132
87
  async add(input) {
133
88
  const tournament = await this.getTournament(input.tournamentId);
134
89
  const matches = input.matches.map(match => {
@@ -137,8 +92,7 @@ let MatchService = class MatchService {
137
92
  });
138
93
  const result = await this.repository.addMatches(input.tournamentId, matches);
139
94
  if (!result)
140
- throw new server_1.TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to add matches' });
141
- await Promise.all(matches.map(match => this.notificationScheduler.scheduleForMatch(match._id, input.tournamentId, match.startingDate)));
95
+ throw (0, error_common_1.notFoundError)('Tournament not found');
142
96
  return result;
143
97
  }
144
98
  async getAll(tournamentId) {
@@ -148,39 +102,35 @@ let MatchService = class MatchService {
148
102
  async start(input) {
149
103
  const tournament = await this.getTournament(input.tournamentId);
150
104
  const match = this.getMatch(tournament, input.matchId);
105
+ if (!match.startingDate || match.startingDate > (0, tournament_utils_1.utcNow)())
106
+ throw (0, error_common_1.badRequestError)('This match has not started yet');
151
107
  if (match.endDate)
152
108
  throw (0, error_common_1.badRequestError)('This match has already ended');
153
- await this.notificationScheduler.cancelForMatch(input.matchId);
154
- return this.applyMatchUpdate(input.tournamentId, input.matchId, { startingDate: new Date() }, 'Failed to start match');
155
- }
156
- async updateScore(input) {
157
- const tournament = await this.getTournament(input.tournamentId);
158
- const match = this.getMatch(tournament, input.matchId);
159
- this.validateWinner(match, input.winnerId);
160
- return this.applyMatchUpdate(input.tournamentId, input.matchId, match_builder_1.MatchBuilder.buildScoreUpdate(input), 'Failed to update match score');
109
+ return match;
161
110
  }
162
111
  async end(input) {
163
112
  const tournament = await this.getTournament(input.tournamentId);
164
113
  const match = this.getMatch(tournament, input.matchId);
165
- this.validateWinner(match, input.winnerId);
166
- const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, match_builder_1.MatchBuilder.buildEndUpdate(input), 'Failed to end match');
114
+ if (!match.startingDate || match.startingDate > (0, tournament_utils_1.utcNow)())
115
+ throw (0, error_common_1.badRequestError)('This match has not started yet');
116
+ if (match.endDate)
117
+ throw (0, error_common_1.badRequestError)('This match has already ended');
118
+ const matchUpdates = match_builder_1.MatchBuilder.buildEndUpdate(match, input.finalScore);
119
+ const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, matchUpdates);
167
120
  const { team1, team2 } = ended.score;
168
121
  if (team1 !== null && team1 !== undefined && team2 !== null && team2 !== undefined) {
169
- await (0, event_1.publishEvent)(new match_ended_event_1.MatchEndedEvent({
170
- tournamentId: input.tournamentId.toString(),
171
- matchId: input.matchId.toString(),
122
+ await (0, event_1.publishEvent)(new evaluate_predictions_event_1.EvaluatePredictionsEvent({
123
+ tournamentId: input.tournamentId,
124
+ matchId: input.matchId,
172
125
  finalScore: { team1, team2 },
173
126
  }));
174
127
  }
175
- await this.notificationService.notifyMatchEnded(input.tournamentId, input.matchId);
176
128
  return ended;
177
129
  }
178
130
  async delete(tournamentId, matchId) {
179
- await this.getTournament(tournamentId);
180
131
  const result = await this.repository.deleteMatch(tournamentId, matchId);
181
132
  if (!result)
182
- throw new server_1.TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to delete match' });
183
- await this.notificationScheduler.cancelForMatch(matchId);
133
+ throw (0, error_common_1.notFoundError)('Tournament not found');
184
134
  return result;
185
135
  }
186
136
  };
@@ -1 +1 @@
1
- {"version":3,"file":"match.service.js","sourceRoot":"/","sources":["modules/tournament/match/match.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,4EAA2F;AAC3F,8DAAkE;AAQlE,yDAA+D;AAC/D,mDAA+C;AAG/C,mGAA8F;AAC9F,+EAAqF;AACrF,4EAAwE;AACxE,+EAA2E;AAC3E,6DAAyD;AACzD,yDAAoD;AACpD,kEAA6D;AAE7D,MAAM,eAAe,GAAG,OAAO,CAAC;AAGzB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACb,UAAU,CAA4B;IACtC,qBAAqB,CAA+B;IACpD,mBAAmB,CAAgC;IACnD,kBAAkB,CAAqB;IACvC,oBAAoB,CAAuB;IAC3C,aAAa,CAAgB;IAErC;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,4CAAyB,CAAC,CAAC;QAC3D,IAAI,CAAC,qBAAqB,GAAG,gBAAS,CAAC,GAAG,CAAC,6DAA4B,CAAC,CAAC;QACzE,IAAI,CAAC,mBAAmB,GAAG,gBAAS,CAAC,GAAG,CAAC,oDA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,KAAK,KAAK,SAAS,EAAE,CAAC;YACjF,MAAM,IAAA,oBAAY,EAAC,IAAI,mCAAe,CAAC;gBACnC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE;gBAC3C,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE;gBACjC,UAAU,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;aAC/B,CAAC,CAAC,CAAC;QACR,CAAC;QAED,MAAM,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAEnF,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAAqC,EAAE,OAAgC;QACvF,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,kBAAS,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAC;QAEvG,MAAM,IAAI,CAAC,qBAAqB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAEzD,OAAO,MAAmC,CAAC;IAC/C,CAAC;CACJ,CAAA;AAzKY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CAyKxB;AAEY,QAAA,YAAY,GAAG,gBAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { mongoose } from '@typegoose/typegoose';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport {\n AddTournamentMatchesInputDTO,\n EndTournamentMatchInputDTO,\n StartTournamentMatchInputDTO,\n TournamentMatchOutputDTO,\n UpdateMatchScoreInputDTO,\n} from './match.validation';\nimport { TournamentMatchRepository } from './match.repository';\nimport { MatchBuilder } from './match.builder';\nimport { TournamentConfigOutputDTO } from '../config/config.validation';\nimport { Tournament as TournamentType } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { NotificationSchedulerService } from '../notification/notification.scheduler.service';\nimport { TournamentNotificationService } from '../notification/notification.service';\nimport { ParticipantService } from '../participant/participant.service';\nimport { PredictionRepository } from '../prediction/prediction.repository';\nimport { RewardService } from '../reward/reward.service';\nimport { RewardType } from '../reward/reward.types';\nimport { MatchEndedEvent } from './events/match-ended.event';\n\nconst FWC_COUPON_CODE = 'FWC01';\n\n@Service()\nexport class MatchService {\n private repository: TournamentMatchRepository;\n private notificationScheduler: NotificationSchedulerService;\n private notificationService: TournamentNotificationService;\n private participantService: ParticipantService;\n private predictionRepository: PredictionRepository;\n private rewardService: RewardService;\n\n constructor() {\n this.repository = Container.get(TournamentMatchRepository);\n this.notificationScheduler = Container.get(NotificationSchedulerService);\n this.notificationService = Container.get(TournamentNotificationService);\n this.participantService = Container.get(ParticipantService);\n this.predictionRepository = Container.get(PredictionRepository);\n this.rewardService = Container.get(RewardService);\n }\n\n private async getTournament(tournamentId: mongoose.Types.ObjectId) {\n const tournament = await this.repository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return tournament;\n }\n\n private getMatch(tournament: { matches: TournamentMatchOutputDTO[] }, matchId: mongoose.Types.ObjectId) {\n const match = tournament.matches.find(m => m._id.toString() === matchId.toString());\n if (!match) throw notFoundError('Match not found');\n return match;\n }\n\n private validateWinner(match: TournamentMatchOutputDTO, winnerId?: mongoose.Types.ObjectId) {\n if (!winnerId) return;\n if (![match.team1.teamId.toString(), match.team2.teamId.toString()].includes(winnerId.toString())) {\n throw badRequestError('Winner must be one of the match teams');\n }\n }\n\n private resolveMatchTeams(tournament: TournamentType, team1Id: mongoose.Types.ObjectId, team2Id: mongoose.Types.ObjectId) {\n const teamsById = new Map(tournament.teams.map(team => [team._id.toString(), team]));\n const team1 = teamsById.get(team1Id.toString());\n const team2 = teamsById.get(team2Id.toString());\n if (!team1 || !team2) throw badRequestError('All match teams must exist in the tournament');\n return { team1, team2 };\n }\n\n private async applyMatchUpdate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n updates: Record<string, unknown>,\n errorMessage: string\n ): Promise<TournamentMatchOutputDTO> {\n const result = await this.repository.updateMatch(tournamentId, matchId, updates);\n if (!result) throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: errorMessage });\n const updated = result.matches.find(m => m._id.toString() === matchId.toString());\n if (!updated) throw notFoundError('Match not found');\n return updated as TournamentMatchOutputDTO;\n }\n\n public async handleMatchEnded(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n finalScore: { team1: number; team2: number }\n ): Promise<void> {\n const participants = await this.participantService.getAll(tournamentId);\n\n await Promise.all(\n participants.map(async participant => {\n const prediction = participant.predictions.find(\n p => p.matchId.toString() === matchId.toString()\n );\n if (!prediction) return;\n\n const correct =\n prediction.score.team1 === finalScore.team1 &&\n prediction.score.team2 === finalScore.team2;\n\n await this.predictionRepository.setSucceeded(participant._id, matchId, correct);\n\n if (correct) {\n const expiresAt = new Date();\n expiresAt.setMonth(expiresAt.getMonth() + 1);\n await this.rewardService.grant(RewardType.COUPON, {\n userId: participant.userId,\n tournamentId,\n matchId,\n payload: { code: FWC_COUPON_CODE, expiresAt },\n });\n }\n })\n );\n }\n\n public async add(input: AddTournamentMatchesInputDTO): Promise<TournamentConfigOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n\n const matches = input.matches.map(match => {\n const { team1, team2 } = this.resolveMatchTeams(tournament, match.team1Id, match.team2Id);\n return MatchBuilder.buildMatch(match, team1, team2);\n });\n\n const result = await this.repository.addMatches(input.tournamentId, matches);\n if (!result) throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to add matches' });\n\n await Promise.all(\n matches.map(match =>\n this.notificationScheduler.scheduleForMatch(match._id, input.tournamentId, match.startingDate!)\n )\n );\n\n return result as TournamentConfigOutputDTO;\n }\n\n public async getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentMatchOutputDTO[]> {\n const tournament = await this.getTournament(tournamentId);\n return tournament.matches as TournamentMatchOutputDTO[];\n }\n\n public async start(input: StartTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (match.endDate) throw badRequestError('This match has already ended');\n\n await this.notificationScheduler.cancelForMatch(input.matchId);\n\n return this.applyMatchUpdate(\n input.tournamentId,\n input.matchId,\n { startingDate: new Date() },\n 'Failed to start match'\n );\n }\n\n public async updateScore(input: UpdateMatchScoreInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n this.validateWinner(match, input.winnerId);\n return this.applyMatchUpdate(input.tournamentId, input.matchId, MatchBuilder.buildScoreUpdate(input), 'Failed to update match score');\n }\n\n public async end(input: EndTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n this.validateWinner(match, input.winnerId);\n\n const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, MatchBuilder.buildEndUpdate(input), 'Failed to end match');\n\n const { team1, team2 } = ended.score;\n if (team1 !== null && team1 !== undefined && team2 !== null && team2 !== undefined) {\n await publishEvent(new MatchEndedEvent({\n tournamentId: input.tournamentId.toString(),\n matchId: input.matchId.toString(),\n finalScore: { team1, team2 },\n }));\n }\n\n await this.notificationService.notifyMatchEnded(input.tournamentId, input.matchId);\n\n return ended;\n }\n\n public async delete(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<TournamentConfigOutputDTO> {\n await this.getTournament(tournamentId);\n const result = await this.repository.deleteMatch(tournamentId, matchId);\n if (!result) throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to delete match' });\n\n await this.notificationScheduler.cancelForMatch(matchId);\n\n return result as TournamentConfigOutputDTO;\n }\n}\n\nexport const matchService = Container.get(MatchService);\n"]}
1
+ {"version":3,"file":"match.service.js","sourceRoot":"/","sources":["modules/tournament/match/match.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,4EAAyF;AACzF,8DAAgE;AAOhE,yDAA6D;AAC7D,mDAA6C;AAG7C,oFAA6E;AAC7E,0DAA2C;AAGpC,IAAM,YAAY,GAAlB,MAAM,YAAY;IACb,UAAU,CAA4B;IAE9C;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,4CAAyB,CAAC,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,YAAqC;QAC7D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAChE,IAAI,CAAC,UAAU;YAAE,MAAM,IAAA,4BAAa,EAAC,sBAAsB,CAAC,CAAC;QAC7D,OAAO,UAAU,CAAC;IACtB,CAAC;IAEO,QAAQ,CAAC,UAAiD,EAAE,OAAgC;QAChG,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK;YAAE,MAAM,IAAA,4BAAa,EAAC,iBAAiB,CAAC,CAAC;QACnD,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,iBAAiB,CAAC,UAA0B,EAAE,OAAgC,EAAE,OAAgC;QACpH,MAAM,SAAS,GAAG,IAAI,GAAG,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xB,IAAA,gBAAO,GAAE;;GACG,YAAY,CA+FxB;AAEY,QAAA,YAAY,GAAG,gBAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {badRequestError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {publishEvent} from '@lyxa.ai/core/dist/libraries/event';\nimport {\n AddTournamentMatchesInputDTO,\n EndTournamentMatchInputDTO,\n StartTournamentMatchInputDTO,\n TournamentMatchOutputDTO,\n} from './match.validation';\nimport {TournamentMatchRepository} from './match.repository';\nimport {MatchBuilder} from './match.builder';\nimport {TournamentConfigOutputDTO} from '../config/config.validation';\nimport {Tournament as TournamentType} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {EvaluatePredictionsEvent} from './events/evaluate-predictions.event';\nimport {utcNow} from '../tournament.utils';\n\n@Service()\nexport class MatchService {\n private repository: TournamentMatchRepository;\n\n constructor() {\n this.repository = Container.get(TournamentMatchRepository);\n }\n\n private async getTournament(tournamentId: mongoose.Types.ObjectId) {\n const tournament = await this.repository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return tournament;\n }\n\n private getMatch(tournament: {matches: TournamentMatchOutputDTO[]}, matchId: mongoose.Types.ObjectId) {\n const match = tournament.matches.find(m => m._id.toString() === matchId.toString());\n if (!match) throw notFoundError('Match not found');\n return match;\n }\n\n private resolveMatchTeams(tournament: TournamentType, team1Id: mongoose.Types.ObjectId, team2Id: mongoose.Types.ObjectId) {\n const teamsById = new Map(tournament.teams.map(team => [team._id.toString(), team]));\n const team1 = teamsById.get(team1Id.toString());\n const team2 = teamsById.get(team2Id.toString());\n if (!team1 || !team2) throw badRequestError('All match teams must exist in the tournament');\n return {team1, team2};\n }\n\n private async applyMatchUpdate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n updates: Record<string, unknown>\n ): Promise<TournamentMatchOutputDTO> {\n const result = await this.repository.updateMatch(tournamentId, matchId, updates);\n if (!result) throw notFoundError('Tournament not found');\n const updated = result.matches.find(m => m._id.toString() === matchId.toString());\n if (!updated) throw notFoundError('Match not found');\n return updated as TournamentMatchOutputDTO;\n }\n\n public async add(input: AddTournamentMatchesInputDTO): Promise<TournamentConfigOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n\n const matches = input.matches.map(match => {\n const {team1, team2} = this.resolveMatchTeams(tournament, match.team1Id, match.team2Id);\n return MatchBuilder.buildMatch(match, team1, team2);\n });\n\n const result = await this.repository.addMatches(input.tournamentId, matches);\n if (!result) throw notFoundError('Tournament not found');\n\n return result as TournamentConfigOutputDTO;\n }\n\n public async getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentMatchOutputDTO[]> {\n const tournament = await this.getTournament(tournamentId);\n return tournament.matches as TournamentMatchOutputDTO[];\n }\n\n public async start(input: StartTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > utcNow()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n return match;\n }\n\n public async end(input: EndTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > utcNow()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n\n const matchUpdates = MatchBuilder.buildEndUpdate(match, input.finalScore)\n const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, matchUpdates);\n\n const {team1, team2} = ended.score;\n if (team1 !== null && team1 !== undefined && team2 !== null && team2 !== undefined) {\n await publishEvent(new EvaluatePredictionsEvent({\n tournamentId: input.tournamentId,\n matchId: input.matchId,\n finalScore: {team1, team2},\n }));\n }\n\n return ended;\n }\n\n public async delete(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<TournamentConfigOutputDTO> {\n const result = await this.repository.deleteMatch(tournamentId, matchId);\n if (!result) throw notFoundError('Tournament not found');\n\n return result as TournamentConfigOutputDTO;\n }\n}\n\nexport const matchService = Container.get(MatchService);\n"]}