41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
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 { ListCommentsQuery } from './list-comments.query.js';
|
|
import { CommentDto } from '../../dto/comment.dto.js';
|
|
import { CommentExpanderService } from '../../services/comment-expander.service.js';
|
|
|
|
@Injectable()
|
|
export class ListCommentsUseCase {
|
|
constructor(
|
|
@Inject(COMMENT_REPOSITORY)
|
|
private readonly commentRepository: ICommentRepository,
|
|
@Inject(ISSUE_REPOSITORY)
|
|
private readonly issueRepository: IIssueRepository,
|
|
private readonly commentExpander: CommentExpanderService,
|
|
) {}
|
|
|
|
async execute(query: ListCommentsQuery): Promise<{ list: CommentDto[]; nextCursor: string | null }> {
|
|
const issue = await this.issueRepository.findById(query.issueId, query.userId);
|
|
if (!issue) {
|
|
throw new IssueNotFoundException(query.issueId);
|
|
}
|
|
|
|
const { list, nextCursor } = await this.commentRepository.findByIssue({
|
|
issueId: query.issueId,
|
|
limit: query.limit,
|
|
cursor: query.cursor,
|
|
direction: query.direction,
|
|
});
|
|
|
|
return { list: await this.commentExpander.expandAll(list), nextCursor };
|
|
}
|
|
}
|