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"; @Injectable() export class TaskPhaseService { constructor( private readonly taskPhaseRepository: TaskPhaseRepository, private readonly projectRepository: ProjectRepository, ) {} findAll(): Promise { return this.taskPhaseRepository.findAll(); } findByProject(projectId: string): Promise { return this.taskPhaseRepository.findByProject(projectId); } async findOne(id: string): Promise { const taskPhase = await this.taskPhaseRepository.findOneById(id); if (!taskPhase) throw new NotFoundException(`TaskPhase #${id} not found`); return taskPhase; } async create(dto: CreateTaskPhaseDto): Promise { const project = await this.projectRepository.findOneById(dto.projectId); if (!project) throw new NotFoundException(`Project #${dto.projectId} not found`); const taskPhase = this.taskPhaseRepository.create(dto); return this.taskPhaseRepository.save(taskPhase); } async update(id: string, dto: UpdateTaskPhaseDto): Promise { 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`); } Object.assign(taskPhase, dto); return this.taskPhaseRepository.save(taskPhase); } async remove(id: string): Promise { await this.findOne(id); await this.taskPhaseRepository.delete(id); } }