import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; import { CommandResult, ack } from './command-result'; import { AssignIssueCommand } from './assign-issue.command'; import { WriteAccess } from './write-access'; @CommandHandler(AssignIssueCommand) export class AssignIssueCommandHandler implements ICommandHandler { constructor(private readonly access: WriteAccess) {} async execute(command: AssignIssueCommand): Promise { const { issue, project } = await this.access.issueForContributor( command.issueId, command.actorId, ); if (command.assigneeId) this.access.assertAssignable(project, command.assigneeId); issue.assign(command.actorId, command.assigneeId); await issue.commitAndWait(); return ack(issue); } }