From 22117c4d248755ae66608802aff97ee8f2b2dfd1 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 22 Apr 2024 11:50:18 +0700 Subject: [PATCH] validate remove kpiPeriod --- src/controllers/KpiPeriodController.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index 943d460..db26d08 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -21,6 +21,7 @@ import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpiPeriod"; import { Like } from "typeorm/browser"; +import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; @Route("api/v1/kpi/period") @Tags("kpiPeriod") @@ -32,6 +33,7 @@ import { Like } from "typeorm/browser"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class kpiPeriodController extends Controller { private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); + private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation); /** * สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ * @param requestBody @@ -205,7 +207,15 @@ export class kpiPeriodController extends Controller { "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้", ); } - + const chkKpiUserEvaluation = await this.kpiUserEvaluationRepository.find({ + where: { kpiPeriodId: id }, + }) + if (chkKpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบข้อมูลได้", + ); + } await this.kpiPeriodRepository.remove(kpiPeriod); return new HttpSuccess(); }