feat: added checklistitem service

This commit is contained in:
2026-07-01 17:10:01 +03:30
parent 6ad18d8f3e
commit c2e0cb1bc6
@@ -0,0 +1,53 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { CheckListItemRepository } from "../repositories/check-list-item.repository";
import { TaskRepository } from "../repositories/task.repository";
import { TMCheckListItem } from "../entities/check-list-item.entity";
import { CreateCheckListItemDto } from "../dto/check-list-item/create-check-list-item.dto";
import { UpdateCheckListItemDto } from "../dto/check-list-item/update-check-list-item.dto";
@Injectable()
export class CheckListItemService {
constructor(
private readonly checkListItemRepository: CheckListItemRepository,
private readonly taskRepository: TaskRepository,
) {}
findAll(): Promise<TMCheckListItem[]> {
return this.checkListItemRepository.findAll();
}
findByTask(taskId: string): Promise<TMCheckListItem[]> {
return this.checkListItemRepository.findByTask(taskId);
}
async findOne(id: string): Promise<TMCheckListItem> {
const checkListItem = await this.checkListItemRepository.findOneById(id);
if (!checkListItem) throw new NotFoundException(`CheckListItem #${id} not found`);
return checkListItem;
}
async create(dto: CreateCheckListItemDto): Promise<TMCheckListItem> {
const task = await this.taskRepository.findOneById(dto.taskId);
if (!task) throw new NotFoundException(`Task #${dto.taskId} not found`);
const checkListItem = this.checkListItemRepository.create(dto);
return this.checkListItemRepository.save(checkListItem);
}
async update(id: string, dto: UpdateCheckListItemDto): Promise<TMCheckListItem> {
const checkListItem = await this.findOne(id);
if (dto.taskId) {
const task = await this.taskRepository.findOneById(dto.taskId);
if (!task) throw new NotFoundException(`Task #${dto.taskId} not found`);
}
Object.assign(checkListItem, dto);
return this.checkListItemRepository.save(checkListItem);
}
async remove(id: string): Promise<void> {
await this.findOne(id);
await this.checkListItemRepository.delete(id);
}
}