import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; import { Comment } from '@task-stream/api/tracker/domain'; import { PurgeCommentCommand } from './purge-comment.command'; import { WriteAccess } from './write-access'; @CommandHandler(PurgeCommentCommand) export class PurgeCommentCommandHandler implements ICommandHandler { constructor(private readonly access: WriteAccess) {} async execute(command: PurgeCommentCommand): Promise { const comment = await this.access.live(command.commentId, Comment); if (!comment || comment.deleted) return; comment.delete(command.actorId, true); await comment.commitAndWait(); } }