tgd-backend/src/socket/socket-handlers/commands-handlers/send-toast-command-handler.ts
2024-11-20 14:24:46 +04:00

20 lines
889 B
TypeScript

import {CommandHandler, ICommandHandler} from '@nestjs/cqrs';
import {SendToastCommand} from '../../../game/commands/send-toast.command';
import {SharedService} from '../../../shared/shared.service';
import {Logger} from "@nestjs/common";
import {ISocketNotificationEvent} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";
@CommandHandler(SendToastCommand)
export class SendToastCommandHandler implements ICommandHandler<SendToastCommand> {
private readonly logger = new Logger(SendToastCommand.name);
constructor(private sharedService: SharedService) {
}
async execute(command: SendToastCommand) {
this.logger.verbose(`send notification: ${command.text}`);
this.sharedService.notifyAllClients<ISocketNotificationEvent>(ClientNotificationType.Notification, {
text: command.text,
timeout: command.timeout,
});
}
}