24 lines
813 B
TypeScript
24 lines
813 B
TypeScript
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<AssignIssueCommand>
|
|
{
|
|
constructor(private readonly access: WriteAccess) {}
|
|
|
|
async execute(command: AssignIssueCommand): Promise<CommandResult> {
|
|
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);
|
|
}
|
|
}
|