@lyxa.ai/marketing 1.0.52 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +307 -61
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +16 -3
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +1117 -285
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.js +16 -2
- package/dist/lib/modules/coupon/validations/all-coupons.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/index.d.ts +0 -1
- package/dist/lib/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/index.js +0 -1
- package/dist/lib/modules/coupon/validations/index.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +32 -32
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +9 -9
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +2 -5
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +2 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +19 -6
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +3 -2
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +3 -9
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +4 -7
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js +15 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +96 -50
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.js +23 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +18 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +78 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +12 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +68 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +22 -18
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +2 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +88 -83
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +3 -2
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +10 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +68 -22
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +2 -2
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +1 -1
- package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
- package/dist/lib/modules/tournament/config/config.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.builder.js +4 -0
- package/dist/lib/modules/tournament/config/config.builder.js.map +1 -1
- package/dist/lib/modules/tournament/config/config.repository.d.ts +8 -2
- package/dist/lib/modules/tournament/config/config.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.repository.js +30 -1
- package/dist/lib/modules/tournament/config/config.repository.js.map +1 -1
- package/dist/lib/modules/tournament/config/config.router.d.ts +92 -2
- package/dist/lib/modules/tournament/config/config.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.types.d.ts +15 -0
- package/dist/lib/modules/tournament/config/config.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.types.js +3 -0
- package/dist/lib/modules/tournament/config/config.types.js.map +1 -0
- package/dist/lib/modules/tournament/config/config.validation.d.ts +395 -15
- package/dist/lib/modules/tournament/config/config.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.validation.js +17 -2
- package/dist/lib/modules/tournament/config/config.validation.js.map +1 -1
- package/dist/lib/modules/tournament/integration/integration.factory.d.ts +4 -0
- package/dist/lib/modules/tournament/integration/integration.factory.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/integration.factory.js +18 -0
- package/dist/lib/modules/tournament/integration/integration.factory.js.map +1 -0
- package/dist/lib/modules/tournament/integration/interfaces/ITournamentService.d.ts +36 -0
- package/dist/lib/modules/tournament/integration/interfaces/ITournamentService.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/interfaces/ITournamentService.js +3 -0
- package/dist/lib/modules/tournament/integration/interfaces/ITournamentService.js.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.provider.d.ts +14 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.provider.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.provider.js +92 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.provider.js.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.types.d.ts +51 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.types.js +3 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/api-football.types.js.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/index.d.ts +3 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/index.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/index.js +19 -0
- package/dist/lib/modules/tournament/integration/providers/api-football/index.js.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/index.d.ts +3 -0
- package/dist/lib/modules/tournament/integration/providers/index.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/index.js +19 -0
- package/dist/lib/modules/tournament/integration/providers/index.js.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/mock.provider.d.ts +7 -0
- package/dist/lib/modules/tournament/integration/providers/mock.provider.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/providers/mock.provider.js +22 -0
- package/dist/lib/modules/tournament/integration/providers/mock.provider.js.map +1 -0
- package/dist/lib/modules/tournament/integration/tournamentService.d.ts +9 -0
- package/dist/lib/modules/tournament/integration/tournamentService.d.ts.map +1 -0
- package/dist/lib/modules/tournament/integration/tournamentService.js +20 -0
- package/dist/lib/modules/tournament/integration/tournamentService.js.map +1 -0
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.js +47 -11
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.js.map +1 -1
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.d.ts +7 -3
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.js +1 -1
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.event.js.map +1 -1
- package/dist/lib/modules/tournament/match/events/match-evaluation.orchestrator.d.ts +14 -0
- package/dist/lib/modules/tournament/match/events/match-evaluation.orchestrator.d.ts.map +1 -0
- package/dist/lib/modules/tournament/{notification/jobs/notification.worker.js → match/events/match-evaluation.orchestrator.js} +31 -27
- package/dist/lib/modules/tournament/match/events/match-evaluation.orchestrator.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.builder.d.ts +13 -34
- package/dist/lib/modules/tournament/match/match.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.builder.js +31 -10
- package/dist/lib/modules/tournament/match/match.builder.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.repository.d.ts +1 -1
- package/dist/lib/modules/tournament/match/match.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.repository.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.router.d.ts +36 -0
- package/dist/lib/modules/tournament/match/match.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.service.d.ts +3 -0
- package/dist/lib/modules/tournament/match/match.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.service.js +15 -12
- package/dist/lib/modules/tournament/match/match.service.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.types.d.ts +51 -0
- package/dist/lib/modules/tournament/match/match.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.types.js +3 -0
- package/dist/lib/modules/tournament/match/match.types.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts +2 -1
- package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/notification-template.repository.js +2 -1
- package/dist/lib/modules/tournament/notification/notification-template.repository.js.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.builder.d.ts +30 -0
- package/dist/lib/modules/tournament/notification/notification.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.builder.js +35 -0
- package/dist/lib/modules/tournament/notification/notification.builder.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.config.d.ts +10 -9
- package/dist/lib/modules/tournament/notification/notification.config.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.config.js +0 -12
- package/dist/lib/modules/tournament/notification/notification.config.js.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.service.d.ts +5 -3
- package/dist/lib/modules/tournament/notification/notification.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.service.js +23 -15
- package/dist/lib/modules/tournament/notification/notification.service.js.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.builder.d.ts +12 -0
- package/dist/lib/modules/tournament/participant/participant.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.builder.js +17 -0
- package/dist/lib/modules/tournament/participant/participant.builder.js.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts +8 -7
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.repository.js +12 -2
- package/dist/lib/modules/tournament/participant/participant.repository.js.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.service.d.ts +1 -0
- package/dist/lib/modules/tournament/participant/participant.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.service.js +15 -17
- package/dist/lib/modules/tournament/participant/participant.service.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts +3 -9
- package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.builder.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts +11 -3
- package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.repository.js +47 -0
- package/dist/lib/modules/tournament/prediction/prediction.repository.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.js +16 -26
- package/dist/lib/modules/tournament/prediction/prediction.service.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.types.d.ts +17 -0
- package/dist/lib/modules/tournament/prediction/prediction.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.types.js +3 -0
- package/dist/lib/modules/tournament/prediction/prediction.types.js.map +1 -0
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +8 -5
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js +58 -16
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.builder.d.ts +5 -2
- package/dist/lib/modules/tournament/reward/reward.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.builder.js +44 -28
- package/dist/lib/modules/tournament/reward/reward.builder.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.factory.d.ts +1 -1
- package/dist/lib/modules/tournament/reward/reward.factory.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.factory.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.interface.d.ts +2 -2
- package/dist/lib/modules/tournament/reward/reward.interface.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.interface.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.service.d.ts +1 -1
- package/dist/lib/modules/tournament/reward/reward.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.service.js +1 -1
- package/dist/lib/modules/tournament/reward/reward.service.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.types.d.ts +35 -2
- package/dist/lib/modules/tournament/reward/reward.types.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.types.js.map +1 -1
- package/dist/lib/modules/tournament/schedule/schedule.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/schedule/schedule.router.js +1 -3
- package/dist/lib/modules/tournament/schedule/schedule.router.js.map +1 -1
- package/dist/lib/modules/tournament/schedule/schedule.service.d.ts +3 -0
- package/dist/lib/modules/tournament/schedule/schedule.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/schedule/schedule.service.js +30 -1
- package/dist/lib/modules/tournament/schedule/schedule.service.js.map +1 -1
- package/dist/lib/modules/tournament/score/score.repository.d.ts +13 -0
- package/dist/lib/modules/tournament/score/score.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/score/score.repository.js +20 -0
- package/dist/lib/modules/tournament/score/score.repository.js.map +1 -1
- package/dist/lib/modules/tournament/score/score.service.d.ts +3 -0
- package/dist/lib/modules/tournament/score/score.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/score/score.service.js +3 -0
- package/dist/lib/modules/tournament/score/score.service.js.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts +5 -0
- package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.builder.js +47 -28
- package/dist/lib/modules/tournament/statistics/statistics.builder.js.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.router.d.ts +4 -2
- package/dist/lib/modules/tournament/statistics/statistics.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.service.js +4 -4
- package/dist/lib/modules/tournament/statistics/statistics.service.js.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts +32 -14
- package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/statistics/statistics.validation.js +2 -1
- package/dist/lib/modules/tournament/statistics/statistics.validation.js.map +1 -1
- package/dist/lib/modules/tournament/sync/sync.repository.d.ts +11 -0
- package/dist/lib/modules/tournament/sync/sync.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/{notification/notification.scheduler.service.js → sync/sync.repository.js} +22 -28
- package/dist/lib/modules/tournament/sync/sync.repository.js.map +1 -0
- package/dist/lib/modules/tournament/sync/sync.router.d.ts +27 -0
- package/dist/lib/modules/tournament/sync/sync.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/sync/sync.router.js +15 -0
- package/dist/lib/modules/tournament/sync/sync.router.js.map +1 -0
- package/dist/lib/modules/tournament/sync/sync.service.d.ts +9 -0
- package/dist/lib/modules/tournament/sync/sync.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/sync/sync.service.js +117 -0
- package/dist/lib/modules/tournament/sync/sync.service.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.builder.d.ts +4 -0
- package/dist/lib/modules/tournament/team/team.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.builder.js +6 -0
- package/dist/lib/modules/tournament/team/team.builder.js.map +1 -1
- package/dist/lib/modules/tournament/team/team.repository.d.ts +3 -0
- package/dist/lib/modules/tournament/team/team.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.repository.js +6 -0
- package/dist/lib/modules/tournament/team/team.repository.js.map +1 -1
- package/dist/lib/modules/tournament/team/team.router.d.ts +22 -4
- package/dist/lib/modules/tournament/team/team.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.router.js +1 -1
- package/dist/lib/modules/tournament/team/team.router.js.map +1 -1
- package/dist/lib/modules/tournament/team/team.service.d.ts +2 -1
- package/dist/lib/modules/tournament/team/team.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.service.js +26 -23
- package/dist/lib/modules/tournament/team/team.service.js.map +1 -1
- package/dist/lib/modules/tournament/team/team.validation.d.ts +23 -24
- package/dist/lib/modules/tournament/team/team.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.validation.js +3 -4
- package/dist/lib/modules/tournament/team/team.validation.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.builder.d.ts +11 -0
- package/dist/lib/modules/tournament/tournament.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/tournament.builder.js +34 -0
- package/dist/lib/modules/tournament/tournament.builder.js.map +1 -0
- package/dist/lib/modules/tournament/tournament.router.d.ts +210 -10
- package/dist/lib/modules/tournament/tournament.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/tournament.router.js +2 -0
- package/dist/lib/modules/tournament/tournament.router.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/tournament.service.js +3 -10
- package/dist/lib/modules/tournament/tournament.service.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.utils.d.ts +4 -0
- package/dist/lib/modules/tournament/tournament.utils.d.ts.map +1 -1
- package/dist/lib/modules/tournament/tournament.utils.js +8 -1
- package/dist/lib/modules/tournament/tournament.utils.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.validation.d.ts +205 -1
- package/dist/lib/modules/tournament/tournament.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/tournament.validation.js +23 -2
- package/dist/lib/modules/tournament/tournament.validation.js.map +1 -1
- package/dist/types/index.d.ts +307 -61
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +1117 -285
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/index.d.ts +0 -1
- package/dist/types/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +34 -32
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +19 -6
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +3 -9
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +96 -50
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +23 -0
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +12 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +22 -18
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +88 -83
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +20 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +2 -2
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +1 -1
- package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
- package/dist/types/modules/tournament/config/config.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/config/config.repository.d.ts +8 -2
- package/dist/types/modules/tournament/config/config.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/config/config.router.d.ts +92 -2
- package/dist/types/modules/tournament/config/config.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/config/config.types.d.ts +15 -0
- package/dist/types/modules/tournament/config/config.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/config.validation.d.ts +395 -15
- package/dist/types/modules/tournament/config/config.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/integration/integration.factory.d.ts +4 -0
- package/dist/types/modules/tournament/integration/integration.factory.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/interfaces/ITournamentService.d.ts +36 -0
- package/dist/types/modules/tournament/integration/interfaces/ITournamentService.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/providers/api-football/api-football.provider.d.ts +14 -0
- package/dist/types/modules/tournament/integration/providers/api-football/api-football.provider.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/providers/api-football/api-football.types.d.ts +51 -0
- package/dist/types/modules/tournament/integration/providers/api-football/api-football.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/providers/api-football/index.d.ts +3 -0
- package/dist/types/modules/tournament/integration/providers/api-football/index.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/providers/index.d.ts +3 -0
- package/dist/types/modules/tournament/integration/providers/index.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/providers/mock.provider.d.ts +7 -0
- package/dist/types/modules/tournament/integration/providers/mock.provider.d.ts.map +1 -0
- package/dist/types/modules/tournament/integration/tournamentService.d.ts +9 -0
- package/dist/types/modules/tournament/integration/tournamentService.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/events/evaluate-predictions.consumer.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/events/evaluate-predictions.event.d.ts +7 -3
- package/dist/types/modules/tournament/match/events/evaluate-predictions.event.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/events/match-evaluation.orchestrator.d.ts +14 -0
- package/dist/types/modules/tournament/match/events/match-evaluation.orchestrator.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.builder.d.ts +13 -34
- package/dist/types/modules/tournament/match/match.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.repository.d.ts +1 -1
- package/dist/types/modules/tournament/match/match.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.router.d.ts +36 -0
- package/dist/types/modules/tournament/match/match.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.service.d.ts +3 -0
- package/dist/types/modules/tournament/match/match.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.types.d.ts +51 -0
- package/dist/types/modules/tournament/match/match.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification-template.repository.d.ts +2 -1
- package/dist/types/modules/tournament/notification/notification-template.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/notification.builder.d.ts +30 -0
- package/dist/types/modules/tournament/notification/notification.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.config.d.ts +10 -9
- package/dist/types/modules/tournament/notification/notification.config.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/notification.service.d.ts +5 -3
- package/dist/types/modules/tournament/notification/notification.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/participant/participant.builder.d.ts +12 -0
- package/dist/types/modules/tournament/participant/participant.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/participant/participant.repository.d.ts +8 -7
- package/dist/types/modules/tournament/participant/participant.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/participant/participant.service.d.ts +1 -0
- package/dist/types/modules/tournament/participant/participant.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.builder.d.ts +3 -9
- package/dist/types/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.repository.d.ts +11 -3
- package/dist/types/modules/tournament/prediction/prediction.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts +1 -1
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.types.d.ts +17 -0
- package/dist/types/modules/tournament/prediction/prediction.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +8 -5
- package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.builder.d.ts +5 -2
- package/dist/types/modules/tournament/reward/reward.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.factory.d.ts +1 -1
- package/dist/types/modules/tournament/reward/reward.factory.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.interface.d.ts +2 -2
- package/dist/types/modules/tournament/reward/reward.interface.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.service.d.ts +1 -1
- package/dist/types/modules/tournament/reward/reward.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.types.d.ts +35 -2
- package/dist/types/modules/tournament/reward/reward.types.d.ts.map +1 -1
- package/dist/types/modules/tournament/schedule/schedule.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/schedule/schedule.service.d.ts +3 -0
- package/dist/types/modules/tournament/schedule/schedule.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/score/score.repository.d.ts +13 -0
- package/dist/types/modules/tournament/score/score.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/score/score.service.d.ts +3 -0
- package/dist/types/modules/tournament/score/score.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/statistics/statistics.builder.d.ts +5 -0
- package/dist/types/modules/tournament/statistics/statistics.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/statistics/statistics.router.d.ts +4 -2
- package/dist/types/modules/tournament/statistics/statistics.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/statistics/statistics.validation.d.ts +32 -14
- package/dist/types/modules/tournament/statistics/statistics.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/sync/sync.repository.d.ts +11 -0
- package/dist/types/modules/tournament/sync/sync.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/sync/sync.router.d.ts +27 -0
- package/dist/types/modules/tournament/sync/sync.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/sync/sync.service.d.ts +9 -0
- package/dist/types/modules/tournament/sync/sync.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.builder.d.ts +4 -0
- package/dist/types/modules/tournament/team/team.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.repository.d.ts +3 -0
- package/dist/types/modules/tournament/team/team.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.router.d.ts +22 -4
- package/dist/types/modules/tournament/team/team.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.service.d.ts +2 -1
- package/dist/types/modules/tournament/team/team.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.validation.d.ts +23 -24
- package/dist/types/modules/tournament/team/team.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.builder.d.ts +11 -0
- package/dist/types/modules/tournament/tournament.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/tournament.router.d.ts +210 -10
- package/dist/types/modules/tournament/tournament.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.utils.d.ts +4 -0
- package/dist/types/modules/tournament/tournament.utils.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.validation.d.ts +205 -1
- package/dist/types/modules/tournament/tournament.validation.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.d.ts +0 -2
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.d.ts.map +0 -1
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.js +0 -15
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.js.map +0 -1
- package/dist/lib/modules/tournament/match/events/match-ended.event.d.ts +0 -14
- package/dist/lib/modules/tournament/match/events/match-ended.event.d.ts.map +0 -1
- package/dist/lib/modules/tournament/match/events/match-ended.event.js +0 -12
- package/dist/lib/modules/tournament/match/events/match-ended.event.js.map +0 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts +0 -10
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts.map +0 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js +0 -23
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js.map +0 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts +0 -9
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts.map +0 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.js.map +0 -1
- package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts +0 -10
- package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts.map +0 -1
- package/dist/lib/modules/tournament/notification/notification.schedule.config.js +0 -15
- package/dist/lib/modules/tournament/notification/notification.schedule.config.js.map +0 -1
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts +0 -10
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts.map +0 -1
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.js.map +0 -1
- package/dist/types/events/event-initializations.d.ts +0 -2
- package/dist/types/events/event-initializations.d.ts.map +0 -1
- package/dist/types/modules/tournament/config/tournament-config.validation.d.ts +0 -201
- package/dist/types/modules/tournament/config/tournament-config.validation.d.ts.map +0 -1
- package/dist/types/modules/tournament/match/events/match-ended.consumer.d.ts +0 -2
- package/dist/types/modules/tournament/match/events/match-ended.consumer.d.ts.map +0 -1
- package/dist/types/modules/tournament/match/events/match-ended.event.d.ts +0 -14
- package/dist/types/modules/tournament/match/events/match-ended.event.d.ts.map +0 -1
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts +0 -10
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts.map +0 -1
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts +0 -9
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts.map +0 -1
- package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts +0 -10
- package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts.map +0 -1
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts +0 -10
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts.map +0 -1
|
@@ -9,6 +9,7 @@ export declare class ParticipantService {
|
|
|
9
9
|
markSeen(userId: mongoose.Types.ObjectId, input: MarkSeenTournamentInputDTO): Promise<void>;
|
|
10
10
|
getByUserAndTournament(userId: mongoose.Types.ObjectId, tournamentId: mongoose.Types.ObjectId): Promise<TournamentParticipantOutputDTO>;
|
|
11
11
|
getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentParticipantOutputDTO[]>;
|
|
12
|
+
getUnpredicted(tournamentId: mongoose.Types.ObjectId, teamIds: mongoose.Types.ObjectId[], matchId: mongoose.Types.ObjectId): Promise<TournamentParticipantOutputDTO[]>;
|
|
12
13
|
}
|
|
13
14
|
export declare const participantService: ParticipantService;
|
|
14
15
|
//# sourceMappingURL=participant.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"participant.service.d.ts","sourceRoot":"/","sources":["modules/tournament/participant/participant.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACH,sBAAsB,EACtB,0BAA0B,EAC1B,8BAA8B,EACjC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"participant.service.d.ts","sourceRoot":"/","sources":["modules/tournament/participant/participant.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACH,sBAAsB,EACtB,0BAA0B,EAC1B,8BAA8B,EACjC,MAAM,0BAA0B,CAAC;AAOlC,qBACa,kBAAkB;IAC3B,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,eAAe,CAA4B;;IAOnD,OAAO,CAAC,gBAAgB;IAKX,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAuB7G,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3F,sBAAsB,CAC/B,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAC/B,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GACtC,OAAO,CAAC,8BAA8B,CAAC;IAM7B,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,8BAA8B,EAAE,CAAC;IAMxF,cAAc,CACvB,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACrC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,EAClC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GACjC,OAAO,CAAC,8BAA8B,EAAE,CAAC;CAM/C;AAED,eAAO,MAAM,kBAAkB,oBAAoC,CAAC"}
|
|
@@ -48,7 +48,9 @@ const server_1 = require("@trpc/server");
|
|
|
48
48
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
49
49
|
const participant_repository_1 = require("./participant.repository");
|
|
50
50
|
const match_repository_1 = require("../match/match.repository");
|
|
51
|
-
const
|
|
51
|
+
const tournament_utils_1 = require("../tournament.utils");
|
|
52
|
+
const participant_builder_1 = require("./participant.builder");
|
|
53
|
+
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
52
54
|
let ParticipantService = class ParticipantService {
|
|
53
55
|
repository;
|
|
54
56
|
matchRepository;
|
|
@@ -65,9 +67,10 @@ let ParticipantService = class ParticipantService {
|
|
|
65
67
|
const tournament = await this.matchRepository.findById(input.tournamentId);
|
|
66
68
|
if (!tournament)
|
|
67
69
|
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
70
|
+
(0, tournament_utils_1.ensureCampaignActive)(tournament);
|
|
68
71
|
this.ensureTeamExists(tournament, input.teamId);
|
|
69
72
|
const existing = await this.repository.findByUserAndTournament(userId, input.tournamentId);
|
|
70
|
-
if (existing?.status ===
|
|
73
|
+
if (existing?.status === enum_1.TournamentParticipantStatus.JOINED)
|
|
71
74
|
throw (0, error_common_1.conflictError)('You have already joined this tournament');
|
|
72
75
|
if (existing) {
|
|
73
76
|
const updated = await this.repository.updateToJoined(userId, input.tournamentId, input.teamId);
|
|
@@ -75,25 +78,14 @@ let ParticipantService = class ParticipantService {
|
|
|
75
78
|
throw new server_1.TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to join tournament' });
|
|
76
79
|
return updated;
|
|
77
80
|
}
|
|
78
|
-
const result = await this.repository.create(
|
|
79
|
-
userId,
|
|
80
|
-
tournamentId: input.tournamentId,
|
|
81
|
-
teamId: input.teamId,
|
|
82
|
-
status: tournament_types_1.TournamentParticipantStatus.JOINED,
|
|
83
|
-
predictions: [],
|
|
84
|
-
});
|
|
85
|
-
if (!result)
|
|
86
|
-
throw new server_1.TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Failed to join tournament' });
|
|
81
|
+
const result = await this.repository.create(participant_builder_1.ParticipantBuilder.buildNewParticipant(userId, input.tournamentId, input.teamId));
|
|
87
82
|
return result;
|
|
88
83
|
}
|
|
89
84
|
async markSeen(userId, input) {
|
|
90
|
-
const
|
|
91
|
-
if (!
|
|
85
|
+
const exists = await this.matchRepository.findById(input.tournamentId);
|
|
86
|
+
if (!exists)
|
|
92
87
|
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
93
|
-
|
|
94
|
-
if (existing)
|
|
95
|
-
return;
|
|
96
|
-
await this.repository.upsertStatus(userId, input.tournamentId, tournament_types_1.TournamentParticipantStatus.SEEN);
|
|
88
|
+
await this.repository.createIfAbsent(userId, input.tournamentId, enum_1.TournamentParticipantStatus.SEEN);
|
|
97
89
|
}
|
|
98
90
|
async getByUserAndTournament(userId, tournamentId) {
|
|
99
91
|
const participant = await this.repository.findByUserAndTournament(userId, tournamentId);
|
|
@@ -107,6 +99,12 @@ let ParticipantService = class ParticipantService {
|
|
|
107
99
|
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
108
100
|
return this.repository.findByTournament(tournamentId);
|
|
109
101
|
}
|
|
102
|
+
async getUnpredicted(tournamentId, teamIds, matchId) {
|
|
103
|
+
const tournament = await this.matchRepository.findById(tournamentId);
|
|
104
|
+
if (!tournament)
|
|
105
|
+
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
106
|
+
return this.repository.findByTournamentWithoutPrediction(tournamentId, teamIds, matchId);
|
|
107
|
+
}
|
|
110
108
|
};
|
|
111
109
|
exports.ParticipantService = ParticipantService;
|
|
112
110
|
exports.ParticipantService = ParticipantService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"participant.service.js","sourceRoot":"/","sources":["modules/tournament/participant/participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAC1C,yCAAuC;AAEvC,4EAAwG;AACxG,qEAAyE;AAMzE,gEAAoE;AAEpE,
|
|
1
|
+
{"version":3,"file":"participant.service.js","sourceRoot":"/","sources":["modules/tournament/participant/participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAC1C,yCAAuC;AAEvC,4EAAwG;AACxG,qEAAyE;AAMzE,gEAAoE;AAEpE,0DAAyD;AACzD,+DAAyD;AACzD,4DAA8E;AAGvE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACnB,UAAU,CAAkC;IAC5C,eAAe,CAA4B;IAEnD;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EM,KAAK,CAAC,cAAc,CACvB,YAAqC,EACrC,OAAkC,EAClC,OAAgC;QAEhC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACrE,IAAI,CAAC,UAAU;YAAE,MAAM,IAAA,4BAAa,EAAC,sBAAsB,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC,UAAU,CAAC,iCAAiC,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7F,CAAC;CAEJ,CAAA;AArEY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,gBAAO,GAAE;;GACG,kBAAkB,CAqE9B;AAEY,QAAA,kBAAkB,GAAG,gBAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {TRPCError} from '@trpc/server';\nimport {mongoose} from '@typegoose/typegoose';\nimport {badRequestError, conflictError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {TournamentParticipantRepository} from './participant.repository';\nimport {\n JoinTournamentInputDTO,\n MarkSeenTournamentInputDTO,\n TournamentParticipantOutputDTO,\n} from './participant.validation';\nimport {TournamentMatchRepository} from '../match/match.repository';\nimport {Tournament as TournamentType} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {ensureCampaignActive} from '../tournament.utils';\nimport {ParticipantBuilder} from './participant.builder';\nimport {TournamentParticipantStatus} from '@lyxa.ai/core/dist/utilities/enum';\n\n@Service()\nexport class ParticipantService {\n private repository: TournamentParticipantRepository;\n private matchRepository: TournamentMatchRepository;\n\n constructor() {\n this.repository = Container.get(TournamentParticipantRepository);\n this.matchRepository = Container.get(TournamentMatchRepository);\n }\n\n private ensureTeamExists(tournament: TournamentType, teamId: mongoose.Types.ObjectId) {\n const exists = tournament.teams.some(team => team._id.toString() === teamId.toString());\n if (!exists) throw badRequestError('Selected team does not exist in this tournament');\n }\n\n public async join(userId: mongoose.Types.ObjectId, input: JoinTournamentInputDTO): Promise<TournamentParticipantOutputDTO> {\n const tournament = await this.matchRepository.findById(input.tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n\n ensureCampaignActive(tournament);\n this.ensureTeamExists(tournament, input.teamId);\n\n const existing = await this.repository.findByUserAndTournament(userId, input.tournamentId);\n if (existing?.status === TournamentParticipantStatus.JOINED) throw conflictError('You have already joined this tournament');\n\n if (existing) {\n const updated = await this.repository.updateToJoined(userId, input.tournamentId, input.teamId);\n if (!updated) throw new TRPCError({code: 'INTERNAL_SERVER_ERROR', message: 'Failed to join tournament'});\n return updated;\n }\n\n const result = await this.repository.create(\n ParticipantBuilder.buildNewParticipant(userId, input.tournamentId, input.teamId)\n );\n\n return result;\n }\n\n public async markSeen(userId: mongoose.Types.ObjectId, input: MarkSeenTournamentInputDTO): Promise<void> {\n const exists = await this.matchRepository.findById(input.tournamentId);\n if (!exists) throw notFoundError('Tournament not found');\n\n await this.repository.createIfAbsent(userId, input.tournamentId, TournamentParticipantStatus.SEEN);\n }\n\n public async getByUserAndTournament(\n userId: mongoose.Types.ObjectId,\n tournamentId: mongoose.Types.ObjectId\n ): Promise<TournamentParticipantOutputDTO> {\n const participant = await this.repository.findByUserAndTournament(userId, tournamentId);\n if (!participant) throw notFoundError('You have not joined this tournament');\n return participant;\n }\n\n public async getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentParticipantOutputDTO[]> {\n const tournament = await this.matchRepository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return this.repository.findByTournament(tournamentId);\n }\n\n public async getUnpredicted(\n tournamentId: mongoose.Types.ObjectId,\n teamIds: mongoose.Types.ObjectId[],\n matchId: mongoose.Types.ObjectId\n ): Promise<TournamentParticipantOutputDTO[]> {\n const tournament = await this.matchRepository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return this.repository.findByTournamentWithoutPrediction(tournamentId, teamIds, matchId);\n }\n\n}\n\nexport const participantService = Container.get(ParticipantService);\n"]}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { mongoose } from '@typegoose/typegoose';
|
|
2
2
|
import { PredictionOutputDTO } from './prediction.validation';
|
|
3
|
-
|
|
4
|
-
team1: number;
|
|
5
|
-
team2: number;
|
|
6
|
-
}
|
|
3
|
+
import { PredictionScoreInput, PredictionScoreUpdate } from './prediction.types';
|
|
7
4
|
export declare class PredictionBuilder {
|
|
8
|
-
static buildPrediction(matchId: mongoose.Types.ObjectId, score: PredictionScoreInput):
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
static buildScoreUpdate(score: PredictionScoreInput): Record<string, unknown>;
|
|
5
|
+
static buildPrediction(matchId: mongoose.Types.ObjectId, score: PredictionScoreInput): PredictionOutputDTO;
|
|
6
|
+
static buildScoreUpdate(score: PredictionScoreInput): PredictionScoreUpdate;
|
|
12
7
|
}
|
|
13
|
-
export {};
|
|
14
8
|
//# sourceMappingURL=prediction.builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.builder.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.builder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"prediction.builder.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAE,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAG/E,qBAAa,iBAAiB;IAC1B,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,oBAAoB,GAAG,mBAAmB;IAU1G,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB;CAM9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.builder.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.builder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"prediction.builder.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.builder.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAG9C,0DAA2C;AAE3C,MAAa,iBAAiB;IAC1B,MAAM,CAAC,eAAe,CAAC,OAAgC,EAAE,KAA2B;QAChF,OAAO;YACH,GAAG,EAAE,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;YAClC,OAAO;YACP,KAAK;YACL,cAAc,EAAE,IAAA,yBAAM,GAAE;YACxB,SAAS,EAAE,IAAI;SAClB,CAAC;IACN,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,KAA2B;QAC/C,OAAO;YACH,qBAAqB,EAAE,KAAK;YAC5B,8BAA8B,EAAE,IAAA,yBAAM,GAAE;SAC3C,CAAC;IACN,CAAC;CACJ;AAjBD,8CAiBC","sourcesContent":["import {mongoose} from '@typegoose/typegoose';\nimport {PredictionOutputDTO} from './prediction.validation';\nimport {PredictionScoreInput, PredictionScoreUpdate} from './prediction.types';\nimport {utcNow} from '../tournament.utils';\n\nexport class PredictionBuilder {\n static buildPrediction(matchId: mongoose.Types.ObjectId, score: PredictionScoreInput): PredictionOutputDTO {\n return {\n _id: new mongoose.Types.ObjectId(),\n matchId,\n score,\n predictionTime: utcNow(),\n succeeded: null,\n };\n }\n\n static buildScoreUpdate(score: PredictionScoreInput): PredictionScoreUpdate {\n return {\n 'predictions.$.score': score,\n 'predictions.$.predictionTime': utcNow(),\n };\n }\n}\n"]}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { mongoose } from '@typegoose/typegoose';
|
|
2
|
-
import {
|
|
2
|
+
import { TournamentParticipantOutputDTO } from '../participant/participant.validation';
|
|
3
3
|
export declare class PredictionRepository {
|
|
4
4
|
private participantModel;
|
|
5
5
|
constructor();
|
|
6
|
-
addPrediction(participantId: mongoose.Types.ObjectId, prediction: object): Promise<
|
|
7
|
-
updatePrediction(participantId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, updates:
|
|
6
|
+
addPrediction(participantId: mongoose.Types.ObjectId, prediction: object): Promise<TournamentParticipantOutputDTO | null>;
|
|
7
|
+
updatePrediction<T extends object>(participantId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, updates: T): Promise<TournamentParticipantOutputDTO | null>;
|
|
8
|
+
setCouponOnPrediction(userIds: mongoose.Types.ObjectId[], tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, couponId: mongoose.Types.ObjectId): Promise<void>;
|
|
8
9
|
evaluate(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, finalScore: {
|
|
9
10
|
team1: number;
|
|
10
11
|
team2: number;
|
|
11
12
|
}): Promise<void>;
|
|
13
|
+
findOutcomeUserIds(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, finalScore: {
|
|
14
|
+
team1: number;
|
|
15
|
+
team2: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
winnerIds: mongoose.Types.ObjectId[];
|
|
18
|
+
loserIds: mongoose.Types.ObjectId[];
|
|
19
|
+
}>;
|
|
12
20
|
}
|
|
13
21
|
export declare const predictionRepository: PredictionRepository;
|
|
14
22
|
//# sourceMappingURL=prediction.repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.repository.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"prediction.repository.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAC,8BAA8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CAAC,QAAQ,EAAE,CAAA;KAAC,CAAC;CA4B1F;AAED,eAAO,MAAM,oBAAoB,sBAAsC,CAAC"}
|
|
@@ -60,6 +60,27 @@ let PredictionRepository = class PredictionRepository {
|
|
|
60
60
|
.findOneAndUpdate({ _id: participantId, 'predictions.matchId': matchId }, { $set: updates }, { new: true })
|
|
61
61
|
.lean();
|
|
62
62
|
}
|
|
63
|
+
async setCouponOnPrediction(userIds, tournamentId, matchId, couponId) {
|
|
64
|
+
const operations = userIds.map((userId) => ({
|
|
65
|
+
updateOne: {
|
|
66
|
+
filter: {
|
|
67
|
+
userId,
|
|
68
|
+
tournamentId,
|
|
69
|
+
},
|
|
70
|
+
update: {
|
|
71
|
+
$set: {
|
|
72
|
+
'predictions.$[pred].coupon': couponId,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
arrayFilters: [
|
|
76
|
+
{
|
|
77
|
+
'pred.matchId': matchId,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
await this.participantModel.bulkWrite(operations);
|
|
83
|
+
}
|
|
63
84
|
async evaluate(tournamentId, matchId, finalScore) {
|
|
64
85
|
const forMatch = { 'pred.matchId': matchId };
|
|
65
86
|
const correctScore = { 'pred.score.team1': finalScore.team1, 'pred.score.team2': finalScore.team2 };
|
|
@@ -81,6 +102,32 @@ let PredictionRepository = class PredictionRepository {
|
|
|
81
102
|
},
|
|
82
103
|
]);
|
|
83
104
|
}
|
|
105
|
+
async findOutcomeUserIds(tournamentId, matchId, finalScore) {
|
|
106
|
+
const winnerMatch = {
|
|
107
|
+
matchId,
|
|
108
|
+
'score.team1': finalScore.team1,
|
|
109
|
+
'score.team2': finalScore.team2,
|
|
110
|
+
};
|
|
111
|
+
const loserMatch = {
|
|
112
|
+
matchId,
|
|
113
|
+
$or: [
|
|
114
|
+
{ 'score.team1': { $ne: finalScore.team1 } },
|
|
115
|
+
{ 'score.team2': { $ne: finalScore.team2 } },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
const [winners, losers] = await Promise.all([
|
|
119
|
+
this.participantModel
|
|
120
|
+
.find({ tournamentId, predictions: { $elemMatch: winnerMatch } }, { userId: 1, _id: 0 })
|
|
121
|
+
.lean(),
|
|
122
|
+
this.participantModel
|
|
123
|
+
.find({ tournamentId, predictions: { $elemMatch: loserMatch } }, { userId: 1, _id: 0 })
|
|
124
|
+
.lean(),
|
|
125
|
+
]);
|
|
126
|
+
return {
|
|
127
|
+
winnerIds: winners.map(w => w.userId),
|
|
128
|
+
loserIds: losers.map(l => l.userId),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
84
131
|
};
|
|
85
132
|
exports.PredictionRepository = PredictionRepository;
|
|
86
133
|
exports.PredictionRepository = PredictionRepository = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.repository.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,
|
|
1
|
+
{"version":3,"file":"prediction.repository.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,sEAAqF;AAI9E,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACrB,gBAAgB,CAAoC;IAE5D;QACI,IAAI,CAAC,gBAAgB,GAAG,mCAA0B,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,aAAsC,EAAE,UAAkB;QAC1E,OAAO,IAAI,CAAC,gBAAgB;aACvB,iBAAiB,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;aACvF,IAAI,EAAoD,CAAC;IAClE,CAA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IAAI,CAAC,EAAC,YAAY,EAAE,WAAW,EAAE,EAAC,UAAU,EAAE,UAAU,EAAC,EAAC,EAAE,EAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;iBAChF,IAAI,EAAkD;SAC9D,CAAC,CAAC;QAEH,OAAO;YACH,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;YACrC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;SACtC,CAAC;IACN,CAAC;CACJ,CAAA;AAlHY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,gBAAO,GAAE;;GACG,oBAAoB,CAkHhC;AAEY,QAAA,oBAAoB,GAAG,gBAAS,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {TournamentParticipantModel} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {TournamentParticipantOutputDTO} from '../participant/participant.validation';\n\n@Service()\nexport class PredictionRepository {\n private participantModel: typeof TournamentParticipantModel;\n\n constructor() {\n this.participantModel = TournamentParticipantModel;\n }\n\n async addPrediction(participantId: mongoose.Types.ObjectId, prediction: object): Promise<TournamentParticipantOutputDTO | null> {\n return this.participantModel\n .findByIdAndUpdate(participantId, { $push: { predictions: prediction } }, { new: true })\n .lean() as Promise<TournamentParticipantOutputDTO | null>;\n }\n\n async updatePrediction<T extends object>(\n participantId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n updates: T\n ): Promise<TournamentParticipantOutputDTO | null> {\n return this.participantModel\n .findOneAndUpdate(\n { _id: participantId, 'predictions.matchId': matchId },\n { $set: updates },\n { new: true }\n )\n .lean() as Promise<TournamentParticipantOutputDTO | null>;\n }\n\n async setCouponOnPrediction(\n userIds: mongoose.Types.ObjectId[],\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n couponId: mongoose.Types.ObjectId\n ): Promise<void> {\n const operations = userIds.map((userId) => ({\n updateOne: {\n filter: {\n userId,\n tournamentId,\n },\n update: {\n $set: {\n 'predictions.$[pred].coupon': couponId,\n },\n },\n arrayFilters: [\n {\n 'pred.matchId': matchId,\n },\n ],\n },\n }));\n\n await this.participantModel.bulkWrite(operations);\n }\n\n async evaluate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n finalScore: {team1: number; team2: number}\n ): Promise<void> {\n const forMatch = {'pred.matchId': matchId};\n const correctScore = {'pred.score.team1': finalScore.team1, 'pred.score.team2': finalScore.team2};\n const incorrectScore = {$or: [{'pred.score.team1': {$ne: finalScore.team1}}, {'pred.score.team2': {$ne: finalScore.team2}}]};\n\n await this.participantModel.bulkWrite([\n {\n updateMany: {\n filter: {tournamentId},\n update: {$set: {'predictions.$[pred].succeeded': true}},\n arrayFilters: [{...forMatch, ...correctScore}],\n },\n },\n {\n updateMany: {\n filter: {tournamentId},\n update: {$set: {'predictions.$[pred].succeeded': false}},\n arrayFilters: [{...forMatch, ...incorrectScore}],\n },\n },\n ]);\n }\n\n async findOutcomeUserIds(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n finalScore: {team1: number; team2: number}\n ): Promise<{winnerIds: mongoose.Types.ObjectId[]; loserIds: mongoose.Types.ObjectId[]}> {\n const winnerMatch = {\n matchId,\n 'score.team1': finalScore.team1,\n 'score.team2': finalScore.team2,\n };\n const loserMatch = {\n matchId,\n $or: [\n {'score.team1': {$ne: finalScore.team1}},\n {'score.team2': {$ne: finalScore.team2}},\n ],\n };\n\n const [winners, losers] = await Promise.all([\n this.participantModel\n .find({tournamentId, predictions: {$elemMatch: winnerMatch}}, {userId: 1, _id: 0})\n .lean() as Promise<{userId: mongoose.Types.ObjectId}[]>,\n this.participantModel\n .find({tournamentId, predictions: {$elemMatch: loserMatch}}, {userId: 1, _id: 0})\n .lean() as Promise<{userId: mongoose.Types.ObjectId}[]>,\n ]);\n\n return {\n winnerIds: winners.map(w => w.userId),\n loserIds: losers.map(l => l.userId),\n };\n }\n}\n\nexport const predictionRepository = Container.get(PredictionRepository);\n"]}
|
|
@@ -10,7 +10,7 @@ export declare class PredictionService {
|
|
|
10
10
|
private ensureMatchInvolvesParticipantTeam;
|
|
11
11
|
private ensureNoPriorPrediction;
|
|
12
12
|
private findPrediction;
|
|
13
|
-
private
|
|
13
|
+
private resolveMutationContext;
|
|
14
14
|
evaluate(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, finalScore: {
|
|
15
15
|
team1: number;
|
|
16
16
|
team2: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.service.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACtB,MAAM,yBAAyB,CAAC;AAQjC,qBACa,iBAAiB;IAC1B,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,kBAAkB,CAAqB;;YAQjC,SAAS;IAQvB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,kCAAkC;IAU1C,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,cAAc;
|
|
1
|
+
{"version":3,"file":"prediction.service.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACtB,MAAM,yBAAyB,CAAC;AAQjC,qBACa,iBAAiB;IAC1B,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,kBAAkB,CAAqB;;YAQjC,SAAS;IAQvB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,kCAAkC;IAU1C,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,cAAc;YAMR,sBAAsB;IAevB,QAAQ,CACjB,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACrC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAChC,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAC7C,OAAO,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;KAAC,CAAC;IAQ1E,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAWtG,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAiBlG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;CAIvH;AAED,eAAO,MAAM,iBAAiB,mBAAmC,CAAC"}
|
|
@@ -66,10 +66,10 @@ let PredictionService = class PredictionService {
|
|
|
66
66
|
const match = tournament.matches.find(m => m._id.toString() === matchId.toString());
|
|
67
67
|
if (!match)
|
|
68
68
|
throw (0, error_common_1.notFoundError)('Match not found');
|
|
69
|
-
return match;
|
|
69
|
+
return { tournament, match };
|
|
70
70
|
}
|
|
71
71
|
ensureMatchIsOpen(match) {
|
|
72
|
-
if (match.endDate)
|
|
72
|
+
if (match.endDate || match.matchEnded)
|
|
73
73
|
throw (0, error_common_1.badRequestError)('This match has already ended');
|
|
74
74
|
if (match.startingDate && match.startingDate <= (0, tournament_utils_1.utcNow)()) {
|
|
75
75
|
throw (0, error_common_1.badRequestError)('The prediction window for this match has closed');
|
|
@@ -94,29 +94,23 @@ let PredictionService = class PredictionService {
|
|
|
94
94
|
throw (0, error_common_1.notFoundError)('No prediction found for this match');
|
|
95
95
|
return prediction;
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const isWinner = prediction.score.team1 === finalScore.team1 && prediction.score.team2 === finalScore.team2;
|
|
105
|
-
(isWinner ? winnerIds : loserIds).push(participant.userId);
|
|
106
|
-
}
|
|
107
|
-
return { winnerIds, loserIds };
|
|
97
|
+
async resolveMutationContext(userId, tournamentId, matchId) {
|
|
98
|
+
const { tournament, match } = await this.findMatch(tournamentId, matchId);
|
|
99
|
+
(0, tournament_utils_1.ensureCampaignActive)(tournament);
|
|
100
|
+
this.ensureMatchIsOpen(match);
|
|
101
|
+
const participant = await this.participantService.getByUserAndTournament(userId, tournamentId);
|
|
102
|
+
this.ensureMatchInvolvesParticipantTeam(match, participant);
|
|
103
|
+
return { match, participant };
|
|
108
104
|
}
|
|
109
105
|
async evaluate(tournamentId, matchId, finalScore) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
const [outcomes] = await Promise.all([
|
|
107
|
+
this.repository.findOutcomeUserIds(tournamentId, matchId, finalScore),
|
|
108
|
+
this.repository.evaluate(tournamentId, matchId, finalScore),
|
|
109
|
+
]);
|
|
113
110
|
return outcomes;
|
|
114
111
|
}
|
|
115
112
|
async create(userId, input) {
|
|
116
|
-
const
|
|
117
|
-
this.ensureMatchIsOpen(match);
|
|
118
|
-
const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);
|
|
119
|
-
this.ensureMatchInvolvesParticipantTeam(match, participant);
|
|
113
|
+
const { participant } = await this.resolveMutationContext(userId, input.tournamentId, input.matchId);
|
|
120
114
|
this.ensureNoPriorPrediction(participant, input.matchId);
|
|
121
115
|
const prediction = prediction_builder_1.PredictionBuilder.buildPrediction(input.matchId, input.score);
|
|
122
116
|
const result = await this.repository.addPrediction(participant._id, prediction);
|
|
@@ -125,10 +119,7 @@ let PredictionService = class PredictionService {
|
|
|
125
119
|
return prediction;
|
|
126
120
|
}
|
|
127
121
|
async edit(userId, input) {
|
|
128
|
-
const
|
|
129
|
-
this.ensureMatchIsOpen(match);
|
|
130
|
-
const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);
|
|
131
|
-
this.ensureMatchInvolvesParticipantTeam(match, participant);
|
|
122
|
+
const { participant } = await this.resolveMutationContext(userId, input.tournamentId, input.matchId);
|
|
132
123
|
this.findPrediction(participant, input.matchId);
|
|
133
124
|
const result = await this.repository.updatePrediction(participant._id, input.matchId, prediction_builder_1.PredictionBuilder.buildScoreUpdate(input.score));
|
|
134
125
|
if (!result)
|
|
@@ -140,8 +131,7 @@ let PredictionService = class PredictionService {
|
|
|
140
131
|
}
|
|
141
132
|
async get(userId, input) {
|
|
142
133
|
const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);
|
|
143
|
-
|
|
144
|
-
return prediction ?? null;
|
|
134
|
+
return participant.predictions.find(p => p.matchId.toString() === input.matchId.toString()) ?? null;
|
|
145
135
|
}
|
|
146
136
|
};
|
|
147
137
|
exports.PredictionService = PredictionService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prediction.service.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,4EAAyF;AAOzF,mEAA6D;AAC7D,6DAAuD;AACvD,4E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OAAO,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChG,IAAI,CAAC,OAAO;YAAE,MAAM,IAAA,4BAAa,EAAC,mCAAmC,CAAC,CAAC;QAEvE,OAAO,OAAyC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAA+B,EAAE,KAA4B;QAC1E,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QACrG,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxG,OAAQ,UAA6C,IAAI,IAAI,CAAC;IAClE,CAAC;CACJ,CAAA;AAtHY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;;GACG,iBAAiB,CAsH7B;AAEY,QAAA,iBAAiB,GAAG,gBAAS,CAAC,GAAG,CAAC,iBAAiB,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 {\n CreatePredictionInputDTO,\n EditPredictionInputDTO,\n GetPredictionInputDTO,\n PredictionOutputDTO\n} from './prediction.validation';\nimport {PredictionRepository} from './prediction.repository';\nimport {PredictionBuilder} from './prediction.builder';\nimport {ParticipantService} from '../participant/participant.service';\nimport {TournamentParticipantOutputDTO} from '../participant/participant.validation';\nimport {TournamentMatchRepository} from '../match/match.repository';\nimport {utcNow} from '../tournament.utils';\n\n@Service()\nexport class PredictionService {\n private repository: PredictionRepository;\n private matchRepository: TournamentMatchRepository;\n private participantService: ParticipantService;\n\n constructor() {\n this.repository = Container.get(PredictionRepository);\n this.matchRepository = Container.get(TournamentMatchRepository);\n this.participantService = Container.get(ParticipantService);\n }\n\n private async findMatch(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId) {\n const tournament = await this.matchRepository.findMatchInTournament(tournamentId, matchId);\n if (!tournament) throw notFoundError('Match not found in this tournament');\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 ensureMatchIsOpen(match: { startingDate?: Date | null; endDate?: Date | null }) {\n if (match.endDate) throw badRequestError('This match has already ended'); // change to flag \"matchEnded\n if (match.startingDate && match.startingDate <= utcNow()) {\n throw badRequestError('The prediction window for this match has closed');\n }\n }\n\n private ensureMatchInvolvesParticipantTeam(\n match: { team1: { teamId: mongoose.Types.ObjectId }; team2: { teamId: mongoose.Types.ObjectId } },\n participant: TournamentParticipantOutputDTO\n ) {\n if (!participant.teamId) throw badRequestError('You have not joined this tournament');\n const teamId = participant.teamId.toString();\n const involved = match.team1.teamId.toString() === teamId || match.team2.teamId.toString() === teamId;\n if (!involved) throw badRequestError('You can only predict for matches involving your selected team');\n }\n\n private ensureNoPriorPrediction(participant: TournamentParticipantOutputDTO, matchId: mongoose.Types.ObjectId) {\n const exists = participant.predictions.some(p => p.matchId.toString() === matchId.toString());\n if (exists) throw badRequestError('You have already predicted for this match');\n }\n\n private findPrediction(participant: TournamentParticipantOutputDTO, matchId: mongoose.Types.ObjectId) {\n const prediction = participant.predictions.find(p => p.matchId.toString() === matchId.toString());\n if (!prediction) throw notFoundError('No prediction found for this match');\n return prediction;\n }\n\n private resolveOutcomes(\n participants: TournamentParticipantOutputDTO[],\n matchId: mongoose.Types.ObjectId,\n finalScore: { team1: number; team2: number }\n ): {winnerIds: mongoose.Types.ObjectId[]; loserIds: mongoose.Types.ObjectId[]} {\n const winnerIds: mongoose.Types.ObjectId[] = [];\n const loserIds: mongoose.Types.ObjectId[] = [];\n\n for (const participant of participants) {\n const prediction = participant.predictions.find(p => p.matchId.toString() === matchId.toString());\n if (!prediction) continue;\n\n const isWinner = prediction.score.team1 === finalScore.team1 && prediction.score.team2 === finalScore.team2;\n (isWinner ? winnerIds : loserIds).push(participant.userId);\n }\n\n return {winnerIds, loserIds};\n }\n\n public async evaluate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n finalScore: { team1: number; team2: number }\n ): Promise<{winnerIds: mongoose.Types.ObjectId[]; loserIds: mongoose.Types.ObjectId[]}> {\n const participants = await this.participantService.getAll(tournamentId);\n const outcomes = this.resolveOutcomes(participants, matchId, finalScore);\n await this.repository.evaluate(tournamentId, matchId, finalScore);\n return outcomes;\n }\n\n public async create(userId: mongoose.Types.ObjectId, input: CreatePredictionInputDTO): Promise<PredictionOutputDTO> {\n const match = await this.findMatch(input.tournamentId, input.matchId);\n this.ensureMatchIsOpen(match);\n\n const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);\n this.ensureMatchInvolvesParticipantTeam(match, participant);\n this.ensureNoPriorPrediction(participant, input.matchId);\n\n const prediction = PredictionBuilder.buildPrediction(input.matchId, input.score);\n const result = await this.repository.addPrediction(participant._id, prediction);\n if (!result) throw notFoundError('Participant not found');\n\n return prediction as PredictionOutputDTO;\n }\n\n public async edit(userId: mongoose.Types.ObjectId, input: EditPredictionInputDTO): Promise<PredictionOutputDTO> {\n const match = await this.findMatch(input.tournamentId, input.matchId);\n this.ensureMatchIsOpen(match);\n\n const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);\n this.ensureMatchInvolvesParticipantTeam(match, participant);\n this.findPrediction(participant, input.matchId);\n\n const result = await this.repository.updatePrediction(\n participant._id,\n input.matchId,\n PredictionBuilder.buildScoreUpdate(input.score)\n );\n if (!result) throw notFoundError('Participant not found');\n\n const updated = result.predictions.find(p => p.matchId.toString() === input.matchId.toString());\n if (!updated) throw notFoundError('Prediction not found after update');\n\n return updated as unknown as PredictionOutputDTO;\n }\n\n public async get(userId: mongoose.Types.ObjectId, input: GetPredictionInputDTO): Promise<PredictionOutputDTO | null> {\n const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);\n const prediction = participant.predictions.find(p => p.matchId.toString() === input.matchId.toString());\n return (prediction as unknown as PredictionOutputDTO) ?? null;\n }\n}\n\nexport const predictionService = Container.get(PredictionService);\n"]}
|
|
1
|
+
{"version":3,"file":"prediction.service.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,4EAAyF;AAOzF,mEAA6D;AAC7D,6DAAuD;AACvD,4EAAsE;AAEtE,gEAAoE;AACpE,0DAAiE;AAG1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAClB,UAAU,CAAuB;IACjC,eAAe,CAA4B;IAC3C,kBAAkB,CAAqB;IAE/C;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,4CAAoB,CAAC,CAAC;QACtD,IAAI,CAAC,eAAe,GAAG,gBAAS,CAAC,GAAG,CAAC,4CAAyB,CAAC,CAAC;QAChE,IAAI,CAAC,kBAAkB,GAAG,gBAAS,CAAC,GAAG,CAAC,wCAAkB,CAAC,CAAC;IAChE,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,YAAqC,EAAE,OAAgC;QAC3F,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3F,IAAI,CAAC,UAAU;YAAE,MAAM,IAAA,4BAAa,EAAC,oCAAoC,CAAC,CAAC;QAC3E,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,4B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AAK,CAAC,GAAG,CAAC,MAA+B,EAAE,KAA4B;QAC1E,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QACrG,OAAO,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC;IACxG,CAAC;CACJ,CAAA;AA1GY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;;GACG,iBAAiB,CA0G7B;AAEY,QAAA,iBAAiB,GAAG,gBAAS,CAAC,GAAG,CAAC,iBAAiB,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 {\n CreatePredictionInputDTO,\n EditPredictionInputDTO,\n GetPredictionInputDTO,\n PredictionOutputDTO\n} from './prediction.validation';\nimport {PredictionRepository} from './prediction.repository';\nimport {PredictionBuilder} from './prediction.builder';\nimport {ParticipantService} from '../participant/participant.service';\nimport {TournamentParticipantOutputDTO} from '../participant/participant.validation';\nimport {TournamentMatchRepository} from '../match/match.repository';\nimport {ensureCampaignActive, utcNow} from '../tournament.utils';\n\n@Service()\nexport class PredictionService {\n private repository: PredictionRepository;\n private matchRepository: TournamentMatchRepository;\n private participantService: ParticipantService;\n\n constructor() {\n this.repository = Container.get(PredictionRepository);\n this.matchRepository = Container.get(TournamentMatchRepository);\n this.participantService = Container.get(ParticipantService);\n }\n\n private async findMatch(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId) {\n const tournament = await this.matchRepository.findMatchInTournament(tournamentId, matchId);\n if (!tournament) throw notFoundError('Match not found in this tournament');\n const match = tournament.matches.find(m => m._id.toString() === matchId.toString());\n if (!match) throw notFoundError('Match not found');\n return {tournament, match};\n }\n\n private ensureMatchIsOpen(match: { startingDate?: Date | null; endDate?: Date | null; matchEnded?: boolean }) {\n if (match.endDate || match.matchEnded) throw badRequestError('This match has already ended');\n if (match.startingDate && match.startingDate <= utcNow()) {\n throw badRequestError('The prediction window for this match has closed');\n }\n }\n\n private ensureMatchInvolvesParticipantTeam(\n match: { team1: { teamId: mongoose.Types.ObjectId }; team2: { teamId: mongoose.Types.ObjectId } },\n participant: TournamentParticipantOutputDTO\n ) {\n if (!participant.teamId) throw badRequestError('You have not joined this tournament');\n const teamId = participant.teamId.toString();\n const involved = match.team1.teamId.toString() === teamId || match.team2.teamId.toString() === teamId;\n if (!involved) throw badRequestError('You can only predict for matches involving your selected team');\n }\n\n private ensureNoPriorPrediction(participant: TournamentParticipantOutputDTO, matchId: mongoose.Types.ObjectId) {\n const exists = participant.predictions.some(p => p.matchId.toString() === matchId.toString());\n if (exists) throw badRequestError('You have already predicted for this match');\n }\n\n private findPrediction(participant: TournamentParticipantOutputDTO, matchId: mongoose.Types.ObjectId) {\n const prediction = participant.predictions.find(p => p.matchId.toString() === matchId.toString());\n if (!prediction) throw notFoundError('No prediction found for this match');\n return prediction;\n }\n\n private async resolveMutationContext(\n userId: mongoose.Types.ObjectId,\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId\n ) {\n const {tournament, match} = await this.findMatch(tournamentId, matchId);\n ensureCampaignActive(tournament);\n this.ensureMatchIsOpen(match);\n\n const participant = await this.participantService.getByUserAndTournament(userId, tournamentId);\n this.ensureMatchInvolvesParticipantTeam(match, participant);\n\n return {match, participant};\n }\n\n public async evaluate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n finalScore: { team1: number; team2: number }\n ): Promise<{winnerIds: mongoose.Types.ObjectId[]; loserIds: mongoose.Types.ObjectId[]}> {\n const [outcomes] = await Promise.all([\n this.repository.findOutcomeUserIds(tournamentId, matchId, finalScore),\n this.repository.evaluate(tournamentId, matchId, finalScore),\n ]);\n return outcomes;\n }\n\n public async create(userId: mongoose.Types.ObjectId, input: CreatePredictionInputDTO): Promise<PredictionOutputDTO> {\n const {participant} = await this.resolveMutationContext(userId, input.tournamentId, input.matchId);\n this.ensureNoPriorPrediction(participant, input.matchId);\n\n const prediction = PredictionBuilder.buildPrediction(input.matchId, input.score);\n const result = await this.repository.addPrediction(participant._id, prediction);\n if (!result) throw notFoundError('Participant not found');\n\n return prediction;\n }\n\n public async edit(userId: mongoose.Types.ObjectId, input: EditPredictionInputDTO): Promise<PredictionOutputDTO> {\n const {participant} = await this.resolveMutationContext(userId, input.tournamentId, input.matchId);\n this.findPrediction(participant, input.matchId);\n\n const result = await this.repository.updatePrediction(\n participant._id,\n input.matchId,\n PredictionBuilder.buildScoreUpdate(input.score)\n );\n if (!result) throw notFoundError('Participant not found');\n\n const updated = result.predictions.find(p => p.matchId.toString() === input.matchId.toString());\n if (!updated) throw notFoundError('Prediction not found after update');\n\n return updated;\n }\n\n public async get(userId: mongoose.Types.ObjectId, input: GetPredictionInputDTO): Promise<PredictionOutputDTO | null> {\n const participant = await this.participantService.getByUserAndTournament(userId, input.tournamentId);\n return participant.predictions.find(p => p.matchId.toString() === input.matchId.toString()) ?? null;\n }\n}\n\nexport const predictionService = Container.get(PredictionService);\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { mongoose } from '@typegoose/typegoose';
|
|
2
|
+
export interface PredictionScoreInput {
|
|
3
|
+
team1: number;
|
|
4
|
+
team2: number;
|
|
5
|
+
}
|
|
6
|
+
export interface BuiltPrediction {
|
|
7
|
+
_id: mongoose.Types.ObjectId;
|
|
8
|
+
matchId: mongoose.Types.ObjectId;
|
|
9
|
+
score: PredictionScoreInput;
|
|
10
|
+
predictionTime: Date;
|
|
11
|
+
succeeded: null;
|
|
12
|
+
}
|
|
13
|
+
export interface PredictionScoreUpdate {
|
|
14
|
+
'predictions.$.score': PredictionScoreInput;
|
|
15
|
+
'predictions.$.predictionTime': Date;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=prediction.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prediction.types.d.ts","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IACjC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,cAAc,EAAE,IAAI,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IAClC,qBAAqB,EAAE,oBAAoB,CAAC;IAC5C,8BAA8B,EAAE,IAAI,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prediction.types.js","sourceRoot":"/","sources":["modules/tournament/prediction/prediction.types.ts"],"names":[],"mappings":"","sourcesContent":["import {mongoose} from '@typegoose/typegoose';\n\nexport interface PredictionScoreInput {\n team1: number;\n team2: number;\n}\n\nexport interface BuiltPrediction {\n _id: mongoose.Types.ObjectId;\n matchId: mongoose.Types.ObjectId;\n score: PredictionScoreInput;\n predictionTime: Date;\n succeeded: null;\n}\n\nexport interface PredictionScoreUpdate {\n 'predictions.$.score': PredictionScoreInput;\n 'predictions.$.predictionTime': Date;\n}\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { IRewardHandler } from '../reward.interface';
|
|
2
|
-
import { RewardContext } from '../reward.types';
|
|
3
|
-
export declare class CouponRewardHandler implements IRewardHandler {
|
|
2
|
+
import { CouponRewardPayload, CouponRewardResult, RewardContext } from '../reward.types';
|
|
3
|
+
export declare class CouponRewardHandler implements IRewardHandler<CouponRewardPayload, CouponRewardResult> {
|
|
4
4
|
private individualUserCouponService;
|
|
5
5
|
private couponService;
|
|
6
|
-
private baseCouponModel;
|
|
7
6
|
constructor();
|
|
8
|
-
private
|
|
9
|
-
|
|
7
|
+
private nextCode;
|
|
8
|
+
private formatCurrency;
|
|
9
|
+
private buildCouponOfferLabel;
|
|
10
|
+
private buildCouponValidityLabel;
|
|
11
|
+
private buildCouponInfo;
|
|
12
|
+
grant(context: RewardContext): Promise<CouponRewardResult>;
|
|
10
13
|
}
|
|
11
14
|
//# sourceMappingURL=coupon-reward.handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coupon-reward.handler.d.ts","sourceRoot":"/","sources":["modules/tournament/reward/handlers/coupon-reward.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"coupon-reward.handler.d.ts","sourceRoot":"/","sources":["modules/tournament/reward/handlers/coupon-reward.handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AASvF,qBACa,mBAAoB,YAAW,cAAc,CAAC,mBAAmB,EAAE,kBAAkB,CAAC;IAC/F,OAAO,CAAC,2BAA2B,CAA8B;IACjE,OAAO,CAAC,aAAa,CAAgB;;YAOvB,QAAQ;IAItB,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,wBAAwB;IAkBhC,OAAO,CAAC,eAAe;IAajB,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAanE"}
|
|
@@ -44,33 +44,75 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.CouponRewardHandler = void 0;
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
-
const
|
|
47
|
+
const reward_builder_1 = require("../reward.builder");
|
|
48
48
|
const individual_user_coupon_service_1 = require("../../../coupon/services/individual-user-coupon.service");
|
|
49
49
|
const coupon_service_1 = require("../../../coupon/services/coupon.service");
|
|
50
|
-
const
|
|
50
|
+
const prediction_repository_1 = require("../../prediction/prediction.repository");
|
|
51
|
+
const core_1 = require("@lyxa.ai/core");
|
|
52
|
+
const currency_1 = require("@lyxa.ai/core/dist/utilities/shared/currency");
|
|
51
53
|
let CouponRewardHandler = class CouponRewardHandler {
|
|
52
54
|
individualUserCouponService;
|
|
53
55
|
couponService;
|
|
54
|
-
baseCouponModel;
|
|
55
56
|
constructor() {
|
|
56
57
|
this.individualUserCouponService = typedi_1.default.get(individual_user_coupon_service_1.IndividualUserCouponService);
|
|
57
58
|
this.couponService = typedi_1.default.get(coupon_service_1.CouponService);
|
|
58
|
-
this.baseCouponModel = models_1.BaseCouponModel;
|
|
59
59
|
}
|
|
60
|
-
async
|
|
61
|
-
|
|
62
|
-
return `${FWC_CODE_PREFIX}${String(count + 1).padStart(2, '0')}`;
|
|
60
|
+
async nextCode(prefix, number) {
|
|
61
|
+
return `${prefix}${String(number).padStart(3, '0')}`;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
formatCurrency(value, secondaryCurrencyValue) {
|
|
64
|
+
const formatterUSD = new Intl.NumberFormat('en-US', {
|
|
65
|
+
minimumFractionDigits: 0,
|
|
66
|
+
maximumFractionDigits: 2,
|
|
67
|
+
});
|
|
68
|
+
const formatterLBP = new Intl.NumberFormat('en-US', {
|
|
69
|
+
minimumFractionDigits: 0,
|
|
70
|
+
});
|
|
71
|
+
if (secondaryCurrencyValue !== null && secondaryCurrencyValue !== undefined) {
|
|
72
|
+
return 'LBP ' + formatterLBP.format(Number(secondaryCurrencyValue));
|
|
73
|
+
}
|
|
74
|
+
return '$' + formatterUSD.format(Number(value ?? 0));
|
|
75
|
+
}
|
|
76
|
+
buildCouponOfferLabel(coupon, exchangeRate) {
|
|
77
|
+
const valuePart = coupon.valueType === 'fixed'
|
|
78
|
+
? this.formatCurrency(coupon.value, (0, currency_1.roundSecondaryCurrency)(coupon.value * exchangeRate))
|
|
79
|
+
: `${coupon.value}%`;
|
|
80
|
+
const maxDiscountPart = coupon.isMaxDiscountLimitEnabled && coupon.maxDiscountLimit && coupon.maxDiscountLimit > 0
|
|
81
|
+
? ` up to ${this.formatCurrency(coupon.maxDiscountLimit, (0, currency_1.roundSecondaryCurrency)(coupon.maxDiscountLimit * exchangeRate))}`
|
|
82
|
+
: '';
|
|
83
|
+
return `Save ${valuePart}${maxDiscountPart}`;
|
|
84
|
+
}
|
|
85
|
+
buildCouponValidityLabel(coupon, exchangeRate) {
|
|
86
|
+
let validityParts = [];
|
|
87
|
+
if (coupon.isMinOrderValueEnabled && coupon.minOrderValue && coupon.minOrderValue > 0) {
|
|
88
|
+
validityParts.push(`Minimum order ${this.formatCurrency(coupon.minOrderValue, (0, currency_1.roundSecondaryCurrency)(coupon.minOrderValue * exchangeRate))}`);
|
|
89
|
+
}
|
|
90
|
+
if (coupon.isOrderLimitPerUserEnabled && coupon.orderLimitPerUser && coupon.orderLimitPerUser > 0) {
|
|
91
|
+
validityParts.push(`Applied on ${coupon.orderLimitPerUser} order`);
|
|
73
92
|
}
|
|
93
|
+
return validityParts.join('. ');
|
|
94
|
+
}
|
|
95
|
+
buildCouponInfo(coupon, exchangeRate) {
|
|
96
|
+
return {
|
|
97
|
+
code: coupon.code,
|
|
98
|
+
duration: {
|
|
99
|
+
start: coupon.duration.start,
|
|
100
|
+
end: coupon.duration.end
|
|
101
|
+
},
|
|
102
|
+
couponOfferLabel: this.buildCouponOfferLabel(coupon, exchangeRate),
|
|
103
|
+
couponValidityLabel: this.buildCouponValidityLabel(coupon, exchangeRate),
|
|
104
|
+
_id: coupon._id
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async grant(context) {
|
|
108
|
+
const { couponNamePrefix } = context.payload;
|
|
109
|
+
const code = await this.nextCode(couponNamePrefix, context.matchNumber);
|
|
110
|
+
const coupon = await this.individualUserCouponService.create(reward_builder_1.RewardBuilder.buildCouponInput(context.payload, code, context.userIds));
|
|
111
|
+
await this.couponService.assignCouponToMultipleUser({ _id: { $in: context.userIds } }, coupon._id);
|
|
112
|
+
await prediction_repository_1.predictionRepository.setCouponOnPrediction(context.userIds, context.tournamentId, context.matchId, coupon._id);
|
|
113
|
+
const settings = (await (0, core_1.getLibraries)().getCachedSettingsService().getSettings());
|
|
114
|
+
const exchangeRate = settings?.currencySetting?.exchangeRate || 1;
|
|
115
|
+
return this.buildCouponInfo(coupon, exchangeRate);
|
|
74
116
|
}
|
|
75
117
|
};
|
|
76
118
|
exports.CouponRewardHandler = CouponRewardHandler;
|