import { CommandHandler } from '@nestjs/cqrs'; import { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { UsernameRepository } from '../../adapters/secondaries/username.repository'; import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command'; @CommandHandler(DeleteAuthenticationCommand) export class DeleteAuthenticationUseCase { constructor( private readonly _authenticationRepository: AuthenticationRepository, private readonly _usernameRepository: UsernameRepository, private readonly _loggingMessager: LoggingMessager, ) {} async execute(command: DeleteAuthenticationCommand) { try { await this._usernameRepository.deleteMany({ uuid: command.deleteAuthenticationRequest.uuid, }); return await this._authenticationRepository.delete( command.deleteAuthenticationRequest.uuid, ); } catch (error) { this._loggingMessager.publish( 'auth.delete.crit', JSON.stringify({ command, error, }), ); throw error; } } }