refactor: refactored the taskphase

This commit is contained in:
2026-07-06 14:26:03 +03:30
parent 5964a9b20d
commit d9283e3a90
6 changed files with 48 additions and 53 deletions
@@ -1,35 +1,36 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { TaskPhaseRepository } from "../repositories/task-phase.repository";
import { ProjectRepository } from "../repositories/project.repository";
import { TMTaskPhase } from "../entities/task-phase.entity";
import { CreateTaskPhaseDto } from "../dto/task-phase/create-task-phase.dto";
import { UpdateTaskPhaseDto } from "../dto/task-phase/update-task-phase.dto";
import { TaskPhaseMessage } from "../../../common/enums/message.enum";
import { ProjectService } from "./project.service";
@Injectable()
export class TaskPhaseService {
constructor(
private readonly taskPhaseRepository: TaskPhaseRepository,
private readonly projectRepository: ProjectRepository,
private readonly projectService: ProjectService
) {}
findAll(): Promise<TMTaskPhase[]> {
return this.taskPhaseRepository.findAll();
return this.taskPhaseRepository.find();
}
findByProject(projectId: string): Promise<TMTaskPhase[]> {
return this.taskPhaseRepository.findByProject(projectId);
return this.taskPhaseRepository.find({
where: {projectId}
});
}
async findOne(id: string): Promise<TMTaskPhase> {
const taskPhase = await this.taskPhaseRepository.findOneById(id);
if (!taskPhase) throw new NotFoundException(`TaskPhase #${id} not found`);
const taskPhase = await this.taskPhaseRepository.findOne({where: {id}});
if (!taskPhase) throw new NotFoundException(TaskPhaseMessage.TASK_PHASE_NOT_FOUND);
return taskPhase;
}
async create(dto: CreateTaskPhaseDto): Promise<TMTaskPhase> {
const project = await this.projectRepository.findOneById(dto.projectId);
if (!project) throw new NotFoundException(`Project #${dto.projectId} not found`);
await this.projectService.findOneOrFail(dto.projectId);
const taskPhase = this.taskPhaseRepository.create(dto);
return this.taskPhaseRepository.save(taskPhase);
}
@@ -38,8 +39,7 @@ export class TaskPhaseService {
const taskPhase = await this.findOne(id);
if (dto.projectId) {
const project = await this.projectRepository.findOneById(dto.projectId);
if (!project) throw new NotFoundException(`Project #${dto.projectId} not found`);
await this.projectService.findOneOrFail(dto.projectId);
}
Object.assign(taskPhase, dto);