34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
|
|
import { CommentFactory } from '@task-stream/api/tracker/domain';
|
|
import { AddCommentCommand } from './add-comment.command';
|
|
import { CommandResult, ack } from './command-result';
|
|
import { WriteAccess } from './write-access';
|
|
|
|
@CommandHandler(AddCommentCommand)
|
|
export class AddCommentCommandHandler
|
|
implements ICommandHandler<AddCommentCommand>
|
|
{
|
|
constructor(
|
|
private readonly access: WriteAccess,
|
|
private readonly commentFactory: CommentFactory,
|
|
private readonly eventPublisher: EventPublisher,
|
|
) {}
|
|
|
|
async execute(command: AddCommentCommand): Promise<CommandResult> {
|
|
const { issue } = await this.access.issueForContributor(
|
|
command.issueId,
|
|
command.actorId,
|
|
);
|
|
const comment = this.commentFactory.create({
|
|
issueId: issue.id,
|
|
projectId: issue.projectId,
|
|
authorId: command.actorId,
|
|
body: command.body,
|
|
});
|
|
|
|
this.eventPublisher.mergeObjectContext(comment);
|
|
await comment.commitAndWait();
|
|
return ack(comment);
|
|
}
|
|
}
|