feat: added task phase APIs

This commit is contained in:
2026-07-01 12:53:42 +03:30
parent 89d85e6d24
commit bf98b8b9ce
6 changed files with 226 additions and 36 deletions
@@ -0,0 +1,53 @@
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<TMTaskPhase[]> {
return this.taskPhaseRepository.findAll();
}
findByProject(projectId: string): Promise<TMTaskPhase[]> {
return this.taskPhaseRepository.findByProject(projectId);
}
async findOne(id: string): Promise<TMTaskPhase> {
const taskPhase = await this.taskPhaseRepository.findOneById(id);
if (!taskPhase) throw new NotFoundException(`TaskPhase #${id} 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`);
const taskPhase = this.taskPhaseRepository.create(dto);
return this.taskPhaseRepository.save(taskPhase);
}
async update(id: string, dto: UpdateTaskPhaseDto): Promise<TMTaskPhase> {
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<void> {
await this.findOne(id);
await this.taskPhaseRepository.delete(id);
}
}