comments implement

This commit is contained in:
vadim committed 2026-10-01 12:02:03 +03:00
1 parent 9e0bef2527
commit 4b6ecfbf5d
41 files changed
+1350 -13

No files matched your search

@@ -0,0 +1,42 @@
import { Inject, Injectable } from '@nestjs/common';
import { COMMENT_REPOSITORY, type ICommentRepository } from '../../../domain/repositories/comment.repository.interface.js';
import { ISSUE_REPOSITORY, type IIssueRepository } from '../../../../issue/domain/repositories/issue.repository.interface.js';
import { IssueNotFoundException } from '../../../../issue/domain/exceptions/issue-not-found.exception.js';
import { Comment } from '../../../domain/entities/comment.entity.js';
import { CreateCommentCommand } from './create-comment.command.js';
import { CommentDto } from '../../dto/comment.dto.js';
import { CommentAuthorExpanderService } from '../../services/comment-author-expander.service.js';
import { CommentEventsService } from '../../services/comment-events.service.js';
@Injectable()
export class CreateCommentUseCase {
constructor(
@Inject(COMMENT_REPOSITORY)
private readonly commentRepository: ICommentRepository,
@Inject(ISSUE_REPOSITORY)
private readonly issueRepository: IIssueRepository,
private readonly commentAuthorExpander: CommentAuthorExpanderService,
private readonly commentEventsService: CommentEventsService,
) {}
async execute(command: CreateCommentCommand): Promise<CommentDto> {
// Комментировать можно только видимую пользователю задачу
const issue = await this.issueRepository.findById(command.issueId, command.authorId);
if (!issue) {
throw new IssueNotFoundException(command.issueId);
}
const comment = Comment.create({
issueId: command.issueId,
authorId: command.authorId,
content: command.content,
});
const saved = await this.commentRepository.create(comment);
const dto = await this.commentAuthorExpander.expand(saved);
this.commentEventsService.emit('comment.created', dto);
return dto;
}
}