import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; import { ProjectKeysRepository } from '../ports/project-keys.repository'; import { CommandResult, ack } from './command-result'; import { DeleteProjectCommand } from './delete-project.command'; import { WriteAccess } from './write-access'; /** Tickets, comments and releases follow through ProjectDeletionSaga. */ @CommandHandler(DeleteProjectCommand) export class DeleteProjectCommandHandler implements ICommandHandler { constructor( private readonly access: WriteAccess, private readonly projectKeys: ProjectKeysRepository, ) {} async execute(command: DeleteProjectCommand): Promise { const project = await this.access.project(command.projectId); project.delete(command.actorId, command.confirmKey); await project.commitAndWait(); // The key can be used again by a new project. await this.projectKeys.release(project.key, project.id); return ack(project); } }