first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { ProjectRole } from '@task-stream/api/tracker/domain';
|
||||
import { CommandResult, ack } from './command-result';
|
||||
import { DeleteCommentCommand } from './delete-comment.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(DeleteCommentCommand)
|
||||
export class DeleteCommentCommandHandler
|
||||
implements ICommandHandler<DeleteCommentCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: DeleteCommentCommand): Promise<CommandResult> {
|
||||
const comment = await this.access.comment(command.commentId);
|
||||
const project = await this.access.project(comment.projectId);
|
||||
const role = project.roleOf(command.actorId);
|
||||
comment.delete(
|
||||
command.actorId,
|
||||
role === ProjectRole.OWNER || role === ProjectRole.ADMIN,
|
||||
);
|
||||
await comment.commitAndWait();
|
||||
return ack(comment);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user