import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; import { GiveOutAPrizeCommand } from '../commands/give-out-a-prize.command'; import { GameService } from '../game.service'; import { Logger } from '@nestjs/common'; import { GameQueueTypes } from '../../schemas/game-queue.schema'; import {GuestsService} from "../../guests/guests.service"; @CommandHandler(GiveOutAPrizeCommand) export class GameGiveOutAPrizeCommandHandler implements ICommandHandler { private readonly logger = new Logger(GameGiveOutAPrizeCommandHandler.name); constructor(private gameService: GameService, private guestService: GuestsService) { } async execute(command: GiveOutAPrizeCommand): Promise { this.logger.verbose(`Player winning a prize ${command.telegramId}`); await this.guestService.incrementPrizeCount(command.telegramId); return this.gameService.addTaskToGameQueue( command.telegramId, GameQueueTypes.giveOutAPrize, ); } }