commit
7b999a670c
243 files changed
+24818
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ISSUE_REPOSITORY, type IIssueRepository } from '../../../domain/repositories/issue.repository.interface.js';
|
||||
import {
|
||||
PROJECT_REPOSITORY,
|
||||
type IProjectRepository,
|
||||
} from '../../../../project/domain/repositories/project.repository.interface.js';
|
||||
import { IssueNotFoundException } from '../../../domain/exceptions/issue-not-found.exception.js';
|
||||
import { UpdateIssueCommand } from './update-issue.command.js';
|
||||
import { IssueWithUsersDto } from '../../dto/issue-with-users.dto.js';
|
||||
import { IssueEventsService } from '../../services/issue-events.service.js';
|
||||
import { IssueUserExpanderService } from '../../services/issue-user-expander.service.js';
|
||||
import { IssueUpdatedEvent } from '../../../domain/events/issue-updated.event.js';
|
||||
|
||||
@Injectable()
|
||||
export class UpdateIssueUseCase {
|
||||
constructor(
|
||||
@Inject(ISSUE_REPOSITORY)
|
||||
private readonly issueRepository: IIssueRepository,
|
||||
@Inject(PROJECT_REPOSITORY)
|
||||
private readonly projectRepository: IProjectRepository,
|
||||
private readonly issueEventsService: IssueEventsService,
|
||||
private readonly issueUserExpander: IssueUserExpanderService,
|
||||
) {}
|
||||
|
||||
async execute(command: UpdateIssueCommand): Promise<IssueWithUsersDto> {
|
||||
const issue = await this.issueRepository.findById(command.id, command.userId);
|
||||
|
||||
if (!issue) {
|
||||
throw new IssueNotFoundException(command.id);
|
||||
}
|
||||
|
||||
if (command.title !== undefined) {
|
||||
issue.updateTitle(command.title);
|
||||
}
|
||||
|
||||
if (command.content !== undefined) {
|
||||
issue.updateContent(command.content);
|
||||
}
|
||||
|
||||
if (command.status !== undefined) {
|
||||
issue.changeStatus(command.status);
|
||||
}
|
||||
|
||||
if (command.priority !== undefined) {
|
||||
issue.changePriority(command.priority);
|
||||
}
|
||||
|
||||
if (command.assignee !== undefined) {
|
||||
if (command.assignee === null || command.assignee === '') {
|
||||
issue.unassign();
|
||||
} else {
|
||||
issue.assignTo(command.assignee);
|
||||
}
|
||||
}
|
||||
|
||||
await this.issueRepository.update(issue);
|
||||
const dto = await this.issueUserExpander.expand(issue);
|
||||
|
||||
if (issue.assignee) {
|
||||
await this.projectRepository.addMember(issue.projectId, issue.assignee);
|
||||
}
|
||||
|
||||
const domainEvents = issue.pullDomainEvents();
|
||||
if (domainEvents.some((event) => event instanceof IssueUpdatedEvent)) {
|
||||
this.issueEventsService.emitIssueUpdated(dto);
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user