@lyxa.ai/marketing 1.0.49 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +236 -17
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.repository.d.ts +3 -0
- package/dist/lib/modules/tournament/config/config.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.repository.js +3 -0
- package/dist/lib/modules/tournament/config/config.repository.js.map +1 -1
- package/dist/lib/modules/tournament/config/config.router.d.ts +10 -10
- package/dist/lib/modules/tournament/config/config.validation.d.ts +37 -36
- package/dist/lib/modules/tournament/config/config.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/config/config.validation.js +4 -3
- package/dist/lib/modules/tournament/config/config.validation.js.map +1 -1
- 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 +9 -1
- package/dist/lib/modules/tournament/match/events/evaluate-predictions.consumer.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.builder.js +2 -1
- package/dist/lib/modules/tournament/match/match.builder.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.repository.d.ts +2 -0
- package/dist/lib/modules/tournament/match/match.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.repository.js +10 -0
- package/dist/lib/modules/tournament/match/match.repository.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.router.d.ts +16 -4
- package/dist/lib/modules/tournament/match/match.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.service.d.ts +0 -1
- package/dist/lib/modules/tournament/match/match.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.service.js +3 -9
- package/dist/lib/modules/tournament/match/match.service.js.map +1 -1
- package/dist/lib/modules/tournament/match/match.validation.d.ts +50 -0
- package/dist/lib/modules/tournament/match/match.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/match/match.validation.js +1 -0
- package/dist/lib/modules/tournament/match/match.validation.js.map +1 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts +2 -5
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js +1 -6
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js.map +1 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts +2 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.js +15 -9
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.js.map +1 -1
- package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts +8 -0
- package/dist/lib/modules/tournament/notification/notification-template.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification-template.repository.js +60 -0
- package/dist/lib/modules/tournament/notification/notification-template.repository.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.config.d.ts +10 -0
- package/dist/lib/modules/tournament/notification/notification.config.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.config.js +15 -0
- package/dist/lib/modules/tournament/notification/notification.config.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts +10 -0
- package/dist/lib/modules/tournament/notification/notification.schedule.config.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.schedule.config.js +15 -0
- package/dist/lib/modules/tournament/notification/notification.schedule.config.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts +4 -4
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.js +15 -28
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.js.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.service.d.ts +5 -4
- package/dist/lib/modules/tournament/notification/notification.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/notification/notification.service.js +33 -28
- package/dist/lib/modules/tournament/notification/notification.service.js.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts +1 -0
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/participant/participant.repository.js +6 -0
- package/dist/lib/modules/tournament/participant/participant.repository.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.builder.js +3 -2
- package/dist/lib/modules/tournament/prediction/prediction.builder.js.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.js +10 -1
- package/dist/lib/modules/tournament/prediction/prediction.service.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.builder.d.ts.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.builder.js +2 -1
- package/dist/lib/modules/tournament/reward/reward.builder.js.map +1 -1
- package/dist/lib/modules/tournament/reward/reward.repository.d.ts +8 -0
- package/dist/lib/modules/tournament/reward/reward.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.repository.js +66 -0
- package/dist/lib/modules/tournament/reward/reward.repository.js.map +1 -0
- package/dist/lib/modules/tournament/schedule/schedule.router.d.ts +27 -0
- package/dist/lib/modules/tournament/schedule/schedule.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/schedule/schedule.router.js +17 -0
- package/dist/lib/modules/tournament/schedule/schedule.router.js.map +1 -0
- package/dist/lib/modules/tournament/schedule/schedule.service.d.ts +10 -0
- package/dist/lib/modules/tournament/schedule/schedule.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/schedule/schedule.service.js +87 -0
- package/dist/lib/modules/tournament/schedule/schedule.service.js.map +1 -0
- package/dist/lib/modules/tournament/score/score.repository.d.ts +8 -1
- package/dist/lib/modules/tournament/score/score.repository.d.ts.map +1 -1
- package/dist/lib/modules/tournament/score/score.repository.js +12 -2
- package/dist/lib/modules/tournament/score/score.repository.js.map +1 -1
- package/dist/lib/modules/tournament/score/score.router.d.ts +98 -0
- package/dist/lib/modules/tournament/score/score.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/score/score.router.js +20 -0
- package/dist/lib/modules/tournament/score/score.router.js.map +1 -0
- package/dist/lib/modules/tournament/score/score.service.d.ts +7 -0
- package/dist/lib/modules/tournament/score/score.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/score/score.service.js +49 -0
- package/dist/lib/modules/tournament/score/score.service.js.map +1 -1
- package/dist/lib/modules/tournament/score/score.validation.d.ts +375 -0
- package/dist/lib/modules/tournament/score/score.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/score/score.validation.js +19 -0
- package/dist/lib/modules/tournament/score/score.validation.js.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts +10 -0
- package/dist/lib/modules/tournament/statistics/statistics.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.builder.js +53 -0
- package/dist/lib/modules/tournament/statistics/statistics.builder.js.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.router.d.ts +80 -0
- package/dist/lib/modules/tournament/statistics/statistics.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.router.js +21 -0
- package/dist/lib/modules/tournament/statistics/statistics.router.js.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.service.d.ts +11 -0
- package/dist/lib/modules/tournament/statistics/statistics.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.service.js +80 -0
- package/dist/lib/modules/tournament/statistics/statistics.service.js.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts +404 -0
- package/dist/lib/modules/tournament/statistics/statistics.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/statistics/statistics.validation.js +36 -0
- package/dist/lib/modules/tournament/statistics/statistics.validation.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.router.d.ts +9 -3
- package/dist/lib/modules/tournament/team/team.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.service.d.ts +1 -0
- package/dist/lib/modules/tournament/team/team.service.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.service.js +21 -16
- package/dist/lib/modules/tournament/team/team.service.js.map +1 -1
- package/dist/lib/modules/tournament/team/team.validation.d.ts +54 -4
- package/dist/lib/modules/tournament/team/team.validation.d.ts.map +1 -1
- package/dist/lib/modules/tournament/team/team.validation.js +4 -2
- package/dist/lib/modules/tournament/team/team.validation.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.router.d.ts +236 -17
- package/dist/lib/modules/tournament/tournament.router.d.ts.map +1 -1
- package/dist/lib/modules/tournament/tournament.router.js +6 -0
- package/dist/lib/modules/tournament/tournament.router.js.map +1 -1
- package/dist/lib/modules/tournament/tournament.types.d.ts +9 -0
- package/dist/lib/modules/tournament/tournament.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/tournament.types.js +14 -0
- package/dist/lib/modules/tournament/tournament.types.js.map +1 -0
- package/dist/lib/modules/tournament/tournament.utils.d.ts +2 -0
- package/dist/lib/modules/tournament/tournament.utils.d.ts.map +1 -0
- package/dist/lib/modules/tournament/tournament.utils.js +6 -0
- package/dist/lib/modules/tournament/tournament.utils.js.map +1 -0
- package/dist/types/index.d.ts +236 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/tournament/config/config.repository.d.ts +3 -0
- package/dist/types/modules/tournament/config/config.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/config/config.router.d.ts +10 -10
- package/dist/types/modules/tournament/config/config.validation.d.ts +37 -36
- package/dist/types/modules/tournament/config/config.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/events/evaluate-predictions.consumer.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.repository.d.ts +2 -0
- package/dist/types/modules/tournament/match/match.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.router.d.ts +16 -4
- package/dist/types/modules/tournament/match/match.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.service.d.ts +0 -1
- package/dist/types/modules/tournament/match/match.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/match/match.validation.d.ts +50 -0
- package/dist/types/modules/tournament/match/match.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts +2 -5
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts +2 -0
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/notification-template.repository.d.ts +8 -0
- package/dist/types/modules/tournament/notification/notification-template.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.config.d.ts +10 -0
- package/dist/types/modules/tournament/notification/notification.config.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts +10 -0
- package/dist/types/modules/tournament/notification/notification.schedule.config.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts +4 -4
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/notification/notification.service.d.ts +5 -4
- package/dist/types/modules/tournament/notification/notification.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/participant/participant.repository.d.ts +1 -0
- package/dist/types/modules/tournament/participant/participant.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts +1 -0
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.builder.d.ts.map +1 -1
- package/dist/types/modules/tournament/reward/reward.repository.d.ts +8 -0
- package/dist/types/modules/tournament/reward/reward.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/schedule/schedule.router.d.ts +27 -0
- package/dist/types/modules/tournament/schedule/schedule.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/schedule/schedule.service.d.ts +10 -0
- package/dist/types/modules/tournament/schedule/schedule.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/score/score.repository.d.ts +8 -1
- package/dist/types/modules/tournament/score/score.repository.d.ts.map +1 -1
- package/dist/types/modules/tournament/score/score.router.d.ts +98 -0
- package/dist/types/modules/tournament/score/score.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/score/score.service.d.ts +7 -0
- package/dist/types/modules/tournament/score/score.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/score/score.validation.d.ts +375 -0
- package/dist/types/modules/tournament/score/score.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/statistics/statistics.builder.d.ts +10 -0
- package/dist/types/modules/tournament/statistics/statistics.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/statistics/statistics.router.d.ts +80 -0
- package/dist/types/modules/tournament/statistics/statistics.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/statistics/statistics.service.d.ts +11 -0
- package/dist/types/modules/tournament/statistics/statistics.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/statistics/statistics.validation.d.ts +404 -0
- package/dist/types/modules/tournament/statistics/statistics.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.router.d.ts +9 -3
- package/dist/types/modules/tournament/team/team.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.service.d.ts +1 -0
- package/dist/types/modules/tournament/team/team.service.d.ts.map +1 -1
- package/dist/types/modules/tournament/team/team.validation.d.ts +54 -4
- package/dist/types/modules/tournament/team/team.validation.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.router.d.ts +236 -17
- package/dist/types/modules/tournament/tournament.router.d.ts.map +1 -1
- package/dist/types/modules/tournament/tournament.types.d.ts +9 -0
- package/dist/types/modules/tournament/tournament.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/tournament.utils.d.ts +2 -0
- package/dist/types/modules/tournament/tournament.utils.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -5,13 +5,21 @@ const evaluate_predictions_event_1 = require("./evaluate-predictions.event");
|
|
|
5
5
|
const prediction_service_1 = require("../../prediction/prediction.service");
|
|
6
6
|
const reward_service_1 = require("../../reward/reward.service");
|
|
7
7
|
const notification_service_1 = require("../../notification/notification.service");
|
|
8
|
+
const notification_template_repository_1 = require("../../notification/notification-template.repository");
|
|
9
|
+
const notification_config_1 = require("../../notification/notification.config");
|
|
8
10
|
const reward_builder_1 = require("../../reward/reward.builder");
|
|
9
11
|
const reward_types_1 = require("../../reward/reward.types");
|
|
10
12
|
const event_1 = require("@lyxa.ai/core/dist/libraries/event");
|
|
11
13
|
async function EvaluatePredictionsConsumer() {
|
|
12
14
|
await (0, event_1.subscribeToEvent)(evaluate_predictions_event_1.TOURNAMENT_EVALUATE_PREDICTIONS_EVENT, async (payload) => {
|
|
13
15
|
const { winnerIds, loserIds } = await prediction_service_1.predictionService.evaluate(payload.tournamentId, payload.matchId, payload.finalScore);
|
|
14
|
-
await
|
|
16
|
+
const templates = await notification_template_repository_1.notificationTemplateRepository.findTemplates(payload.tournamentId);
|
|
17
|
+
const winner = templates.get(notification_config_1.NotificationTag.MATCH_RESULT_WINNER);
|
|
18
|
+
const loser = templates.get(notification_config_1.NotificationTag.MATCH_RESULT_LOSER);
|
|
19
|
+
await Promise.all([
|
|
20
|
+
winner && winnerIds.length > 0 ? notification_service_1.tournamentNotificationService.notifyUsers(winner.title, winner.body, winnerIds) : Promise.resolve(),
|
|
21
|
+
loser && loserIds.length > 0 ? notification_service_1.tournamentNotificationService.notifyUsers(loser.title, loser.body, loserIds) : Promise.resolve(),
|
|
22
|
+
]);
|
|
15
23
|
if (winnerIds.length > 0) {
|
|
16
24
|
await reward_service_1.rewardService.grant(reward_types_1.RewardType.COUPON, reward_builder_1.RewardBuilder.buildCouponRewardContext(payload.matchId, payload.tournamentId, winnerIds));
|
|
17
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate-predictions.consumer.js","sourceRoot":"/","sources":["modules/tournament/match/events/evaluate-predictions.consumer.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"evaluate-predictions.consumer.js","sourceRoot":"/","sources":["modules/tournament/match/events/evaluate-predictions.consumer.ts"],"names":[],"mappings":";;AAUA,kEAoBC;AA9BD,6EAA+G;AAC/G,4EAAsE;AACtE,gEAA0D;AAC1D,kFAAsF;AACtF,0GAAmG;AACnG,gFAAuE;AACvE,gEAA0D;AAC1D,4DAAqD;AACrD,8DAAoE;AAE7D,KAAK,UAAU,2BAA2B;IAC7C,MAAM,IAAA,wBAAgB,EAAC,kEAAqC,EAAE,KAAK,EAAE,OAAmC,EAAE,EAAE;QACxG,MAAM,EAAC,SAAS,EAAE,QAAQ,EAAC,GAAG,MAAM,sCAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAE1H,MAAM,SAAS,GAAG,MAAM,iEAA8B,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC3F,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,qCAAe,CAAC,mBAAmB,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,qCAAe,CAAC,kBAAkB,CAAC,CAAC;QAEhE,MAAM,OAAO,CAAC,GAAG,CAAC;YACd,MAAM,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,oDAA6B,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE;YACpI,KAAK,IAAK,QAAQ,CAAC,MAAM,GAAI,CAAC,CAAC,CAAC,CAAC,oDAA6B,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAG,KAAK,CAAC,IAAI,EAAG,QAAQ,CAAC,CAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE;SACvI,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,8BAAa,CAAC,KAAK,CACrB,yBAAU,CAAC,MAAM,EACjB,8BAAa,CAAC,wBAAwB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAC3F,CAAC;QACN,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {EvaluatePredictionsPayload, TOURNAMENT_EVALUATE_PREDICTIONS_EVENT} from './evaluate-predictions.event';\nimport {predictionService} from '../../prediction/prediction.service';\nimport {rewardService} from '../../reward/reward.service';\nimport {tournamentNotificationService} from '../../notification/notification.service';\nimport {notificationTemplateRepository} from '../../notification/notification-template.repository';\nimport {NotificationTag} from '../../notification/notification.config';\nimport {RewardBuilder} from '../../reward/reward.builder';\nimport {RewardType} from '../../reward/reward.types';\nimport {subscribeToEvent} from '@lyxa.ai/core/dist/libraries/event';\n\nexport async function EvaluatePredictionsConsumer() {\n await subscribeToEvent(TOURNAMENT_EVALUATE_PREDICTIONS_EVENT, async (payload: EvaluatePredictionsPayload) => {\n const {winnerIds, loserIds} = await predictionService.evaluate(payload.tournamentId, payload.matchId, payload.finalScore);\n\n const templates = await notificationTemplateRepository.findTemplates(payload.tournamentId);\n const winner = templates.get(NotificationTag.MATCH_RESULT_WINNER);\n const loser = templates.get(NotificationTag.MATCH_RESULT_LOSER);\n\n await Promise.all([\n winner && winnerIds.length > 0 ? tournamentNotificationService.notifyUsers(winner.title, winner.body, winnerIds) : Promise.resolve(),\n loser && loserIds.length > 0 ? tournamentNotificationService.notifyUsers(loser.title, loser.body, loserIds) : Promise.resolve(),\n ]);\n\n if (winnerIds.length > 0) {\n await rewardService.grant(\n RewardType.COUPON,\n RewardBuilder.buildCouponRewardContext(payload.matchId, payload.tournamentId, winnerIds)\n );\n }\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.builder.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,wBAAwB,EAAE,wBAAwB,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"match.builder.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,wBAAwB,EAAE,wBAAwB,EAAC,MAAM,oBAAoB,CAAC;AAGtF,UAAU,YAAY;IAClB,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,qBAAa,YAAY;IACrB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;IAc7E,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQjF,MAAM,CAAC,cAAc,CACjB,KAAK,EAAE,wBAAwB,EAC/B,UAAU,CAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,GAC5C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAc7B"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MatchBuilder = void 0;
|
|
4
4
|
const typegoose_1 = require("@typegoose/typegoose");
|
|
5
|
+
const tournament_utils_1 = require("../tournament.utils");
|
|
5
6
|
class MatchBuilder {
|
|
6
7
|
static buildMatch(input, team1, team2) {
|
|
7
8
|
return {
|
|
@@ -32,7 +33,7 @@ class MatchBuilder {
|
|
|
32
33
|
: team2 > team1 ? match.team2.teamId
|
|
33
34
|
: null
|
|
34
35
|
: null;
|
|
35
|
-
const update = { endDate:
|
|
36
|
+
const update = { endDate: (0, tournament_utils_1.utcNow)(), winnerId };
|
|
36
37
|
if (finalScore)
|
|
37
38
|
update.score = finalScore;
|
|
38
39
|
return update;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.builder.js","sourceRoot":"/","sources":["modules/tournament/match/match.builder.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;
|
|
1
|
+
{"version":3,"file":"match.builder.js","sourceRoot":"/","sources":["modules/tournament/match/match.builder.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAE9C,0DAA2C;AAc3C,MAAa,YAAY;IACrB,MAAM,CAAC,UAAU,CAAC,KAAiB,EAAE,KAAmB,EAAE,KAAmB;QACzE,OAAO;YACH,GAAG,EAAE,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;YAClC,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,EAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAC;YAC5C,KAAK,EAAE,EAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAC;YAC5C,KAAK,EAAE,EAAC,KAA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{utcNow} from '../tournament.utils';\n\ninterface MatchTeamRef {\n _id: mongoose.Types.ObjectId;\n name: string;\n}\n\ninterface MatchInput {\n stage: string;\n additionalTag?: string;\n startingDate: Date;\n endDate?: Date;\n}\n\nexport class MatchBuilder {\n static buildMatch(input: MatchInput, team1: MatchTeamRef, team2: MatchTeamRef) {\n return {\n _id: new mongoose.Types.ObjectId(),\n additionalTag: input.additionalTag,\n stage: input.stage,\n team1: {teamId: team1._id, name: team1.name},\n team2: {teamId: team2._id, name: team2.name},\n score: {team1: null, team2: null},\n winnerId: null,\n startingDate: input.startingDate,\n endDate: input.endDate,\n };\n }\n\n static buildScoreUpdate(input: UpdateMatchScoreInputDTO): Record<string, unknown> {\n const updates: Record<string, unknown> = {\n score: {team1: input.team1Score, team2: input.team2Score},\n };\n if (input.winnerId !== undefined) updates.winnerId = input.winnerId;\n return updates;\n }\n\n static buildEndUpdate(\n match: TournamentMatchOutputDTO,\n finalScore?: {team1: number; team2: number}\n ): Record<string, unknown> {\n const score = finalScore ?? match.score;\n const {team1, team2} = score;\n const winnerId =\n team1 !== null && team2 !== null\n ? team1 > team2 ? match.team1.teamId\n : team2 > team1 ? match.team2.teamId\n : null\n : null;\n\n const update: Record<string, unknown> = {endDate: utcNow(), winnerId};\n if (finalScore) update.score = finalScore;\n return update;\n }\n}\n"]}
|
|
@@ -8,6 +8,8 @@ export declare class TournamentMatchRepository {
|
|
|
8
8
|
updateMatch(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, updates: Record<string, unknown>): Promise<Model | null>;
|
|
9
9
|
deleteMatch(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<Model | null>;
|
|
10
10
|
findMatchInTournament(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<Model | null>;
|
|
11
|
+
getNotificationFlag(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, type: string): Promise<boolean>;
|
|
12
|
+
setNotificationFlag(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, type: string): Promise<void>;
|
|
11
13
|
}
|
|
12
14
|
export declare const tournamentMatchRepository: TournamentMatchRepository;
|
|
13
15
|
//# sourceMappingURL=match.repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.repository.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,IAAI,KAAK,EAAmB,MAAM,2CAA2C,CAAC;AAEjG,qBACa,yBAAyB;IACrC,OAAO,CAAC,KAAK,CAAyB;;IAMhC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAI5D,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAMjF,WAAW,CAChB,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACrC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAalB,WAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAM3G,qBAAqB,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"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QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM/H;AAED,eAAO,MAAM,yBAAyB,2BAA2C,CAAC"}
|
|
@@ -74,6 +74,16 @@ let TournamentMatchRepository = class TournamentMatchRepository {
|
|
|
74
74
|
.findOne({ _id: tournamentId, 'matches._id': matchId })
|
|
75
75
|
.lean();
|
|
76
76
|
}
|
|
77
|
+
async getNotificationFlag(tournamentId, matchId, type) {
|
|
78
|
+
const doc = await this.model
|
|
79
|
+
.findOne({ _id: tournamentId, 'matches._id': matchId }, { 'matches.$': 1 })
|
|
80
|
+
.lean();
|
|
81
|
+
const match = doc?.matches?.[0];
|
|
82
|
+
return match?.notificationFlags?.[type] === true;
|
|
83
|
+
}
|
|
84
|
+
async setNotificationFlag(tournamentId, matchId, type) {
|
|
85
|
+
await this.model.updateOne({ _id: tournamentId, 'matches._id': matchId }, { $set: { [`matches.$.notificationFlags.${type}`]: true } });
|
|
86
|
+
}
|
|
77
87
|
};
|
|
78
88
|
exports.TournamentMatchRepository = TournamentMatchRepository;
|
|
79
89
|
exports.TournamentMatchRepository = TournamentMatchRepository = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.repository.js","sourceRoot":"/","sources":["modules/tournament/match/match.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAE5C,sEAAiG;AAG1F,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAC7B,KAAK,CAAyB;IAEtC;QACC,IAAI,CAAC,KAAK,GAAG,wBAAe,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAA2B;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAA2B,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,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G,gBAAS,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { mongoose } from '@typegoose/typegoose';\nimport { Tournament as Model, TournamentModel } from '@lyxa.ai/core/dist/libraries/mongo/models';\n\n@Service()\nexport class TournamentMatchRepository {\n\tprivate model: typeof TournamentModel;\n\n\tconstructor() {\n\t\tthis.model = TournamentModel;\n\t}\n\n\tasync findById(id: mongoose.Types.ObjectId): Promise<Model | null> {\n\t\treturn this.model.findById(id).lean() as Promise<Model | null>;\n\t}\n\n\tasync addMatches(id: mongoose.Types.ObjectId, matches: object[]): Promise<Model | null> {\n\t\treturn this.model\n\t\t\t.findByIdAndUpdate(id, { $push: { matches: { $each: matches } } }, { new: true })\n\t\t\t.lean() as Promise<Model | null>;\n\t}\n\n\tasync updateMatch(\n\t\ttournamentId: mongoose.Types.ObjectId,\n\t\tmatchId: mongoose.Types.ObjectId,\n\t\tupdates: Record<string, unknown>\n\t): Promise<Model | null> {\n\t\tconst setUpdates = Object.fromEntries(\n\t\t\tObject.entries(updates).map(([key, value]) => [`matches.$.${key}`, value])\n\t\t);\n\t\treturn this.model\n\t\t\t.findOneAndUpdate(\n\t\t\t\t{ _id: tournamentId, 'matches._id': matchId },\n\t\t\t\t{ $set: setUpdates },\n\t\t\t\t{ new: true }\n\t\t\t)\n\t\t\t.lean() as Promise<Model | null>;\n\t}\n\n\tasync deleteMatch(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<Model | null> {\n\t\treturn this.model\n\t\t\t.findByIdAndUpdate(tournamentId, { $pull: { matches: { _id: matchId } } }, { new: true })\n\t\t\t.lean() as Promise<Model | null>;\n\t}\n\n\tasync findMatchInTournament(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<Model | null> {\n\t\treturn this.model\n\t\t\t.findOne({ _id: tournamentId, 'matches._id': matchId })\n\t\t\t.lean() as Promise<Model | null>;\n\t}\n\n\tasync getNotificationFlag(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, type: string): Promise<boolean> {\n\t\tconst doc = await this.model\n\t\t\t.findOne({ _id: tournamentId, 'matches._id': matchId }, { 'matches.$': 1 })\n\t\t\t.lean();\n\t\tconst match = doc?.matches?.[0] as any;\n\t\treturn match?.notificationFlags?.[type] === true;\n\t}\n\n\tasync setNotificationFlag(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId, type: string): Promise<void> {\n\t\tawait this.model.updateOne(\n\t\t\t{ _id: tournamentId, 'matches._id': matchId },\n\t\t\t{ $set: { [`matches.$.notificationFlags.${type}`]: true } }\n\t\t);\n\t}\n}\n\nexport const tournamentMatchRepository = Container.get(TournamentMatchRepository);\n"]}
|
|
@@ -32,12 +32,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
32
32
|
data?: {
|
|
33
33
|
status: import("@lyxa.ai/core/dist/utilities/enum").Status;
|
|
34
34
|
name: string;
|
|
35
|
-
tag: string;
|
|
36
35
|
_id?: string | import("mongoose").Types.ObjectId | undefined;
|
|
37
36
|
createdAt?: Date | null | undefined;
|
|
38
37
|
startDate?: Date | null | undefined;
|
|
39
38
|
endDate?: Date | null | undefined;
|
|
40
39
|
updatedAt?: Date | null | undefined;
|
|
40
|
+
tag?: import("../tournament.types").TournamentTag | undefined;
|
|
41
41
|
reward?: {
|
|
42
42
|
type: import("@lyxa.ai/core/dist/utilities/enum").TournamentRewardType.FREE_DELIVERY;
|
|
43
43
|
} | {
|
|
@@ -50,12 +50,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
50
50
|
documents: {
|
|
51
51
|
status: import("@lyxa.ai/core/dist/utilities/enum").Status;
|
|
52
52
|
name: string;
|
|
53
|
-
tag: string;
|
|
54
53
|
_id?: string | import("mongoose").Types.ObjectId | undefined;
|
|
55
54
|
createdAt?: Date | null | undefined;
|
|
56
55
|
startDate?: Date | null | undefined;
|
|
57
56
|
endDate?: Date | null | undefined;
|
|
58
57
|
updatedAt?: Date | null | undefined;
|
|
58
|
+
tag?: import("../tournament.types").TournamentTag | undefined;
|
|
59
59
|
reward?: {
|
|
60
60
|
type: import("@lyxa.ai/core/dist/utilities/enum").TournamentRewardType.FREE_DELIVERY;
|
|
61
61
|
} | {
|
|
@@ -87,10 +87,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
87
87
|
team1: {
|
|
88
88
|
name: string;
|
|
89
89
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
90
|
+
picture?: string | undefined;
|
|
90
91
|
};
|
|
91
92
|
team2: {
|
|
92
93
|
name: string;
|
|
93
94
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
95
|
+
picture?: string | undefined;
|
|
94
96
|
};
|
|
95
97
|
score: {
|
|
96
98
|
team1: number | null;
|
|
@@ -114,10 +116,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
114
116
|
team1: {
|
|
115
117
|
name: string;
|
|
116
118
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
119
|
+
picture?: string | undefined;
|
|
117
120
|
};
|
|
118
121
|
team2: {
|
|
119
122
|
name: string;
|
|
120
123
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
124
|
+
picture?: string | undefined;
|
|
121
125
|
};
|
|
122
126
|
score: {
|
|
123
127
|
team1: number | null;
|
|
@@ -159,10 +163,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
159
163
|
team1: {
|
|
160
164
|
name: string;
|
|
161
165
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
166
|
+
picture?: string | undefined;
|
|
162
167
|
};
|
|
163
168
|
team2: {
|
|
164
169
|
name: string;
|
|
165
170
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
171
|
+
picture?: string | undefined;
|
|
166
172
|
};
|
|
167
173
|
score: {
|
|
168
174
|
team1: number | null;
|
|
@@ -186,10 +192,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
186
192
|
team1: {
|
|
187
193
|
name: string;
|
|
188
194
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
195
|
+
picture?: string | undefined;
|
|
189
196
|
};
|
|
190
197
|
team2: {
|
|
191
198
|
name: string;
|
|
192
199
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
200
|
+
picture?: string | undefined;
|
|
193
201
|
};
|
|
194
202
|
score: {
|
|
195
203
|
team1: number | null;
|
|
@@ -235,10 +243,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
235
243
|
team1: {
|
|
236
244
|
name: string;
|
|
237
245
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
246
|
+
picture?: string | undefined;
|
|
238
247
|
};
|
|
239
248
|
team2: {
|
|
240
249
|
name: string;
|
|
241
250
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
251
|
+
picture?: string | undefined;
|
|
242
252
|
};
|
|
243
253
|
score: {
|
|
244
254
|
team1: number | null;
|
|
@@ -262,10 +272,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
262
272
|
team1: {
|
|
263
273
|
name: string;
|
|
264
274
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
275
|
+
picture?: string | undefined;
|
|
265
276
|
};
|
|
266
277
|
team2: {
|
|
267
278
|
name: string;
|
|
268
279
|
teamId: string | import("mongoose").Types.ObjectId;
|
|
280
|
+
picture?: string | undefined;
|
|
269
281
|
};
|
|
270
282
|
score: {
|
|
271
283
|
team1: number | null;
|
|
@@ -305,12 +317,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
305
317
|
data?: {
|
|
306
318
|
status: import("@lyxa.ai/core/dist/utilities/enum").Status;
|
|
307
319
|
name: string;
|
|
308
|
-
tag: string;
|
|
309
320
|
_id?: string | import("mongoose").Types.ObjectId | undefined;
|
|
310
321
|
createdAt?: Date | null | undefined;
|
|
311
322
|
startDate?: Date | null | undefined;
|
|
312
323
|
endDate?: Date | null | undefined;
|
|
313
324
|
updatedAt?: Date | null | undefined;
|
|
325
|
+
tag?: import("../tournament.types").TournamentTag | undefined;
|
|
314
326
|
reward?: {
|
|
315
327
|
type: import("@lyxa.ai/core/dist/utilities/enum").TournamentRewardType.FREE_DELIVERY;
|
|
316
328
|
} | {
|
|
@@ -323,12 +335,12 @@ export declare const matchRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
323
335
|
documents: {
|
|
324
336
|
status: import("@lyxa.ai/core/dist/utilities/enum").Status;
|
|
325
337
|
name: string;
|
|
326
|
-
tag: string;
|
|
327
338
|
_id?: string | import("mongoose").Types.ObjectId | undefined;
|
|
328
339
|
createdAt?: Date | null | undefined;
|
|
329
340
|
startDate?: Date | null | undefined;
|
|
330
341
|
endDate?: Date | null | undefined;
|
|
331
342
|
updatedAt?: Date | null | undefined;
|
|
343
|
+
tag?: import("../tournament.types").TournamentTag | undefined;
|
|
332
344
|
reward?: {
|
|
333
345
|
type: import("@lyxa.ai/core/dist/utilities/enum").TournamentRewardType.FREE_DELIVERY;
|
|
334
346
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.router.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.router.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"match.router.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.router.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDtB,CAAC"}
|
|
@@ -3,7 +3,6 @@ import { AddTournamentMatchesInputDTO, EndTournamentMatchInputDTO, StartTourname
|
|
|
3
3
|
import { TournamentConfigOutputDTO } from '../config/config.validation';
|
|
4
4
|
export declare class MatchService {
|
|
5
5
|
private repository;
|
|
6
|
-
private notificationScheduler;
|
|
7
6
|
constructor();
|
|
8
7
|
private getTournament;
|
|
9
8
|
private getMatch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.service.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACH,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EAC3B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAKtE,qBACa,YAAY;IACrB,OAAO,CAAC,UAAU,CAA4B
|
|
1
|
+
{"version":3,"file":"match.service.d.ts","sourceRoot":"/","sources":["modules/tournament/match/match.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACH,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EAC3B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAKtE,qBACa,YAAY;IACrB,OAAO,CAAC,UAAU,CAA4B;;YAMhC,aAAa;IAM3B,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,iBAAiB;YAQX,gBAAgB;IAYjB,GAAG,CAAC,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAc5E,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAKlF,KAAK,CAAC,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAS7E,GAAG,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAsBzE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAMnI;AAED,eAAO,MAAM,YAAY,cAA8B,CAAC"}
|
|
@@ -48,14 +48,12 @@ const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
|
48
48
|
const event_1 = require("@lyxa.ai/core/dist/libraries/event");
|
|
49
49
|
const match_repository_1 = require("./match.repository");
|
|
50
50
|
const match_builder_1 = require("./match.builder");
|
|
51
|
-
const notification_scheduler_service_1 = require("../notification/notification.scheduler.service");
|
|
52
51
|
const evaluate_predictions_event_1 = require("./events/evaluate-predictions.event");
|
|
52
|
+
const tournament_utils_1 = require("../tournament.utils");
|
|
53
53
|
let MatchService = class MatchService {
|
|
54
54
|
repository;
|
|
55
|
-
notificationScheduler;
|
|
56
55
|
constructor() {
|
|
57
56
|
this.repository = typedi_1.default.get(match_repository_1.TournamentMatchRepository);
|
|
58
|
-
this.notificationScheduler = typedi_1.default.get(notification_scheduler_service_1.NotificationSchedulerService);
|
|
59
57
|
}
|
|
60
58
|
async getTournament(tournamentId) {
|
|
61
59
|
const tournament = await this.repository.findById(tournamentId);
|
|
@@ -95,7 +93,6 @@ let MatchService = class MatchService {
|
|
|
95
93
|
const result = await this.repository.addMatches(input.tournamentId, matches);
|
|
96
94
|
if (!result)
|
|
97
95
|
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
98
|
-
await Promise.all(matches.map(match => this.notificationScheduler.scheduleForMatch(match._id, input.tournamentId, match.startingDate)));
|
|
99
96
|
return result;
|
|
100
97
|
}
|
|
101
98
|
async getAll(tournamentId) {
|
|
@@ -105,17 +102,16 @@ let MatchService = class MatchService {
|
|
|
105
102
|
async start(input) {
|
|
106
103
|
const tournament = await this.getTournament(input.tournamentId);
|
|
107
104
|
const match = this.getMatch(tournament, input.matchId);
|
|
108
|
-
if (!match.startingDate || match.startingDate >
|
|
105
|
+
if (!match.startingDate || match.startingDate > (0, tournament_utils_1.utcNow)())
|
|
109
106
|
throw (0, error_common_1.badRequestError)('This match has not started yet');
|
|
110
107
|
if (match.endDate)
|
|
111
108
|
throw (0, error_common_1.badRequestError)('This match has already ended');
|
|
112
|
-
await this.notificationScheduler.cancelForMatch(input.matchId);
|
|
113
109
|
return match;
|
|
114
110
|
}
|
|
115
111
|
async end(input) {
|
|
116
112
|
const tournament = await this.getTournament(input.tournamentId);
|
|
117
113
|
const match = this.getMatch(tournament, input.matchId);
|
|
118
|
-
if (!match.startingDate || match.startingDate >
|
|
114
|
+
if (!match.startingDate || match.startingDate > (0, tournament_utils_1.utcNow)())
|
|
119
115
|
throw (0, error_common_1.badRequestError)('This match has not started yet');
|
|
120
116
|
if (match.endDate)
|
|
121
117
|
throw (0, error_common_1.badRequestError)('This match has already ended');
|
|
@@ -132,11 +128,9 @@ let MatchService = class MatchService {
|
|
|
132
128
|
return ended;
|
|
133
129
|
}
|
|
134
130
|
async delete(tournamentId, matchId) {
|
|
135
|
-
await this.getTournament(tournamentId);
|
|
136
131
|
const result = await this.repository.deleteMatch(tournamentId, matchId);
|
|
137
132
|
if (!result)
|
|
138
133
|
throw (0, error_common_1.notFoundError)('Tournament not found');
|
|
139
|
-
await this.notificationScheduler.cancelForMatch(matchId);
|
|
140
134
|
return result;
|
|
141
135
|
}
|
|
142
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.service.js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IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM;YAAE,MAAM,IAAA,4BAAa,EAAC,sBAAsB,CAAC,CAAC;QAEzD,MAAM,IAAI,CAAC,qBAAqB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAEzD,OAAO,MAAmC,CAAC;IAC/C,CAAC;CACJ,CAAA;AA5GY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CA4GxB;AAEY,QAAA,YAAY,GAAG,gBAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {badRequestError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {publishEvent} from '@lyxa.ai/core/dist/libraries/event';\nimport {\n AddTournamentMatchesInputDTO,\n EndTournamentMatchInputDTO,\n StartTournamentMatchInputDTO,\n TournamentMatchOutputDTO,\n} from './match.validation';\nimport {TournamentMatchRepository} from './match.repository';\nimport {MatchBuilder} from './match.builder';\nimport {TournamentConfigOutputDTO} from '../config/config.validation';\nimport {Tournament as TournamentType} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {NotificationSchedulerService} from '../notification/notification.scheduler.service';\nimport {EvaluatePredictionsEvent} from './events/evaluate-predictions.event';\n\n@Service()\nexport class MatchService {\n private repository: TournamentMatchRepository;\n private notificationScheduler: NotificationSchedulerService;\n\n constructor() {\n this.repository = Container.get(TournamentMatchRepository);\n this.notificationScheduler = Container.get(NotificationSchedulerService);\n }\n\n private async getTournament(tournamentId: mongoose.Types.ObjectId) {\n const tournament = await this.repository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return tournament;\n }\n\n private getMatch(tournament: {matches: TournamentMatchOutputDTO[]}, matchId: mongoose.Types.ObjectId) {\n const match = tournament.matches.find(m => m._id.toString() === matchId.toString());\n if (!match) throw notFoundError('Match not found');\n return match;\n }\n\n private resolveMatchTeams(tournament: TournamentType, team1Id: mongoose.Types.ObjectId, team2Id: mongoose.Types.ObjectId) {\n const teamsById = new Map(tournament.teams.map(team => [team._id.toString(), team]));\n const team1 = teamsById.get(team1Id.toString());\n const team2 = teamsById.get(team2Id.toString());\n if (!team1 || !team2) throw badRequestError('All match teams must exist in the tournament');\n return {team1, team2};\n }\n\n private async applyMatchUpdate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n updates: Record<string, unknown>\n ): Promise<TournamentMatchOutputDTO> {\n const result = await this.repository.updateMatch(tournamentId, matchId, updates);\n if (!result) throw notFoundError('Tournament not found');\n const updated = result.matches.find(m => m._id.toString() === matchId.toString());\n if (!updated) throw notFoundError('Match not found');\n return updated as TournamentMatchOutputDTO;\n }\n\n public async add(input: AddTournamentMatchesInputDTO): Promise<TournamentConfigOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n\n const matches = input.matches.map(match => {\n const {team1, team2} = this.resolveMatchTeams(tournament, match.team1Id, match.team2Id);\n return MatchBuilder.buildMatch(match, team1, team2);\n });\n\n const result = await this.repository.addMatches(input.tournamentId, matches);\n if (!result) throw notFoundError('Tournament not found');\n\n await Promise.all(\n matches.map(match =>\n this.notificationScheduler.scheduleForMatch(match._id, input.tournamentId, match.startingDate!)\n )\n );\n\n return result as TournamentConfigOutputDTO;\n }\n\n public async getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentMatchOutputDTO[]> {\n const tournament = await this.getTournament(tournamentId);\n return tournament.matches as TournamentMatchOutputDTO[];\n }\n\n public async start(input: StartTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > new Date()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n\n await this.notificationScheduler.cancelForMatch(input.matchId);\n return match;\n }\n\n public async end(input: EndTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > new Date()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n\n const matchUpdates = MatchBuilder.buildEndUpdate(match, input.finalScore)\n const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, matchUpdates);\n\n const {team1, team2} = ended.score;\n if (team1 !== null && team1 !== undefined && team2 !== null && team2 !== undefined) {\n await publishEvent(new EvaluatePredictionsEvent({\n tournamentId: input.tournamentId,\n matchId: input.matchId,\n finalScore: {team1, team2},\n }));\n }\n\n return ended;\n }\n\n public async delete(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<TournamentConfigOutputDTO> {\n await this.getTournament(tournamentId);\n const result = await this.repository.deleteMatch(tournamentId, matchId);\n if (!result) throw notFoundError('Tournament not found');\n\n await this.notificationScheduler.cancelForMatch(matchId);\n\n return result as TournamentConfigOutputDTO;\n }\n}\n\nexport const matchService = Container.get(MatchService);\n"]}
|
|
1
|
+
{"version":3,"file":"match.service.js","sourceRoot":"/","sources":["modules/tournament/match/match.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,4EAAyF;AACzF,8DAAgE;AAOhE,yDAA6D;AAC7D,mDAA6C;AAG7C,oFAA6E;AAC7E,0DAA2C;AAGpC,IAAM,YAAY,GAAlB,MAAM,YAAY;IACb,UAAU,CAA4B;IAE9C;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,4CAAyB,CAAC,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,YAAqC;QAC7D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAChE,IAAI,CAA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C;gBAC5C,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,UAAU,EAAE,EAAC,KAAK,EAAE,KAAK,EAAC;aAC7B,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAAqC,EAAE,OAAgC;QACvF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM;YAAE,MAAM,IAAA,4BAAa,EAAC,sBAAsB,CAAC,CAAC;QAEzD,OAAO,MAAmC,CAAC;IAC/C,CAAC;CACJ,CAAA;AA/FY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CA+FxB;AAEY,QAAA,YAAY,GAAG,gBAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {badRequestError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {publishEvent} from '@lyxa.ai/core/dist/libraries/event';\nimport {\n AddTournamentMatchesInputDTO,\n EndTournamentMatchInputDTO,\n StartTournamentMatchInputDTO,\n TournamentMatchOutputDTO,\n} from './match.validation';\nimport {TournamentMatchRepository} from './match.repository';\nimport {MatchBuilder} from './match.builder';\nimport {TournamentConfigOutputDTO} from '../config/config.validation';\nimport {Tournament as TournamentType} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {EvaluatePredictionsEvent} from './events/evaluate-predictions.event';\nimport {utcNow} from '../tournament.utils';\n\n@Service()\nexport class MatchService {\n private repository: TournamentMatchRepository;\n\n constructor() {\n this.repository = Container.get(TournamentMatchRepository);\n }\n\n private async getTournament(tournamentId: mongoose.Types.ObjectId) {\n const tournament = await this.repository.findById(tournamentId);\n if (!tournament) throw notFoundError('Tournament not found');\n return tournament;\n }\n\n private getMatch(tournament: {matches: TournamentMatchOutputDTO[]}, matchId: mongoose.Types.ObjectId) {\n const match = tournament.matches.find(m => m._id.toString() === matchId.toString());\n if (!match) throw notFoundError('Match not found');\n return match;\n }\n\n private resolveMatchTeams(tournament: TournamentType, team1Id: mongoose.Types.ObjectId, team2Id: mongoose.Types.ObjectId) {\n const teamsById = new Map(tournament.teams.map(team => [team._id.toString(), team]));\n const team1 = teamsById.get(team1Id.toString());\n const team2 = teamsById.get(team2Id.toString());\n if (!team1 || !team2) throw badRequestError('All match teams must exist in the tournament');\n return {team1, team2};\n }\n\n private async applyMatchUpdate(\n tournamentId: mongoose.Types.ObjectId,\n matchId: mongoose.Types.ObjectId,\n updates: Record<string, unknown>\n ): Promise<TournamentMatchOutputDTO> {\n const result = await this.repository.updateMatch(tournamentId, matchId, updates);\n if (!result) throw notFoundError('Tournament not found');\n const updated = result.matches.find(m => m._id.toString() === matchId.toString());\n if (!updated) throw notFoundError('Match not found');\n return updated as TournamentMatchOutputDTO;\n }\n\n public async add(input: AddTournamentMatchesInputDTO): Promise<TournamentConfigOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n\n const matches = input.matches.map(match => {\n const {team1, team2} = this.resolveMatchTeams(tournament, match.team1Id, match.team2Id);\n return MatchBuilder.buildMatch(match, team1, team2);\n });\n\n const result = await this.repository.addMatches(input.tournamentId, matches);\n if (!result) throw notFoundError('Tournament not found');\n\n return result as TournamentConfigOutputDTO;\n }\n\n public async getAll(tournamentId: mongoose.Types.ObjectId): Promise<TournamentMatchOutputDTO[]> {\n const tournament = await this.getTournament(tournamentId);\n return tournament.matches as TournamentMatchOutputDTO[];\n }\n\n public async start(input: StartTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > utcNow()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n return match;\n }\n\n public async end(input: EndTournamentMatchInputDTO): Promise<TournamentMatchOutputDTO> {\n const tournament = await this.getTournament(input.tournamentId);\n const match = this.getMatch(tournament, input.matchId);\n\n if (!match.startingDate || match.startingDate > utcNow()) throw badRequestError('This match has not started yet');\n if (match.endDate) throw badRequestError('This match has already ended');\n\n const matchUpdates = MatchBuilder.buildEndUpdate(match, input.finalScore)\n const ended = await this.applyMatchUpdate(input.tournamentId, input.matchId, matchUpdates);\n\n const {team1, team2} = ended.score;\n if (team1 !== null && team1 !== undefined && team2 !== null && team2 !== undefined) {\n await publishEvent(new EvaluatePredictionsEvent({\n tournamentId: input.tournamentId,\n matchId: input.matchId,\n finalScore: {team1, team2},\n }));\n }\n\n return ended;\n }\n\n public async delete(tournamentId: mongoose.Types.ObjectId, matchId: mongoose.Types.ObjectId): Promise<TournamentConfigOutputDTO> {\n const result = await this.repository.deleteMatch(tournamentId, matchId);\n if (!result) throw notFoundError('Tournament not found');\n\n return result as TournamentConfigOutputDTO;\n }\n}\n\nexport const matchService = Container.get(MatchService);\n"]}
|