import { CommandHandler } from '@nestjs/cqrs'; import { UserMessager } from '../../adapters/secondaries/user.messager'; import { UsersRepository } from '../../adapters/secondaries/users.repository'; import { DeleteUserCommand } from '../../commands/delete-user.command'; import { User } from '../entities/user'; @CommandHandler(DeleteUserCommand) export class DeleteUserUseCase { constructor( private readonly _repository: UsersRepository, private readonly _messager: UserMessager, ) {} async execute(command: DeleteUserCommand): Promise { const user = await this._repository.delete(command.uuid); if (user) { this._messager.publish( 'user.delete', JSON.stringify({ uuid: user.uuid }), ); } return user; } }