From c2e0cb1bc64c7ca8ec99cdae660a47a20fbb1048 Mon Sep 17 00:00:00 2001 From: realrafi Date: Wed, 1 Jul 2026 17:10:01 +0330 Subject: [PATCH] feat: added checklistitem service --- .../providers/check-list-item.service.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/modules/task-manager/providers/check-list-item.service.ts diff --git a/src/modules/task-manager/providers/check-list-item.service.ts b/src/modules/task-manager/providers/check-list-item.service.ts new file mode 100644 index 0000000..f421db4 --- /dev/null +++ b/src/modules/task-manager/providers/check-list-item.service.ts @@ -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 { + return this.checkListItemRepository.findAll(); + } + + findByTask(taskId: string): Promise { + return this.checkListItemRepository.findByTask(taskId); + } + + async findOne(id: string): Promise { + const checkListItem = await this.checkListItemRepository.findOneById(id); + if (!checkListItem) throw new NotFoundException(`CheckListItem #${id} not found`); + return checkListItem; + } + + async create(dto: CreateCheckListItemDto): Promise { + 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 { + 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 { + await this.findOne(id); + await this.checkListItemRepository.delete(id); + } +}