32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { filter, type Observable } from 'rxjs';
|
|
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 { WatchIssueCommentsQuery } from './watch-issue-comments.query.js';
|
|
import { type CommentEvent, CommentEventsService } from '../../services/comment-events.service.js';
|
|
|
|
/**
|
|
* Поток событий комментариев одной задачи для SSE. Доступ к задаче
|
|
* проверяется один раз — при подключении.
|
|
*/
|
|
@Injectable()
|
|
export class WatchIssueCommentsUseCase {
|
|
constructor(
|
|
@Inject(ISSUE_REPOSITORY)
|
|
private readonly issueRepository: IIssueRepository,
|
|
private readonly commentEventsService: CommentEventsService,
|
|
) {}
|
|
|
|
async execute(query: WatchIssueCommentsQuery): Promise<Observable<CommentEvent>> {
|
|
const issue = await this.issueRepository.findById(query.issueId, query.userId);
|
|
if (!issue) {
|
|
throw new IssueNotFoundException(query.issueId);
|
|
}
|
|
|
|
return this.commentEventsService.onEvents().pipe(filter((event) => event.comment.issueId === query.issueId));
|
|
}
|
|
}
|