26 lines
983 B
TypeScript
26 lines
983 B
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { ISSUE_REPOSITORY, type IIssueRepository } from '../../../domain/repositories/issue.repository.interface.js';
|
|
import { IssueNotFoundException } from '../../../domain/exceptions/issue-not-found.exception.js';
|
|
import { GetIssueQuery } from './get-issue.query.js';
|
|
import { IssueWithUsersDto } from '../../dto/issue-with-users.dto.js';
|
|
import { IssueUserExpanderService } from '../../services/issue-user-expander.service.js';
|
|
|
|
@Injectable()
|
|
export class GetIssueUseCase {
|
|
constructor(
|
|
@Inject(ISSUE_REPOSITORY)
|
|
private readonly issueRepository: IIssueRepository,
|
|
private readonly issueUserExpander: IssueUserExpanderService,
|
|
) {}
|
|
|
|
async execute(query: GetIssueQuery): Promise<IssueWithUsersDto> {
|
|
const issue = await this.issueRepository.findById(query.id, query.userId);
|
|
|
|
if (!issue) {
|
|
throw new IssueNotFoundException(query.id);
|
|
}
|
|
|
|
return this.issueUserExpander.expand(issue);
|
|
}
|
|
}
|