import { Injectable, NotFoundException } from "@nestjs/common"; import { RemarkRepository } from "../repositories/remark.repository"; import { TMRemark } from "../entities/remark.entity"; import { CreateRemarkDto } from "../dto/remark/create-remark.dto"; import { UpdateRemarkDto } from "../dto/remark/update-remark.dto"; import { remarkMessage } from "../../../common/enums/message.enum"; import { TaskService } from './task.service'; @Injectable() export class RemarkService { constructor( private readonly remarkRepository: RemarkRepository, private readonly taskService: TaskService, ) {} async findOneOrFail(id: string): Promise { const remark = await this.remarkRepository.findOne({ where: { id } }); if (!remark) throw new NotFoundException(remarkMessage.REMARK_NOT_FOUND); return remark; } async create(dto: CreateRemarkDto): Promise { await this.taskService.findOneOrFail(dto.taskId); const remark = this.remarkRepository.create(dto); return this.remarkRepository.save(remark); } async update(id: string, dto: UpdateRemarkDto): Promise { const remark = await this.findOneOrFail(id); if (dto.taskId) { await this.taskService.findOneOrFail(dto.taskId); } Object.assign(remark, dto); return this.remarkRepository.save(remark); } async remove(id: string): Promise { await this.findOneOrFail(id); await this.remarkRepository.delete(id); } }