From 17f110d3459b44445a5fbd1f66657f7735b06ae5 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 19 Apr 2024 17:13:45 +0700 Subject: [PATCH] delete --- src/controllers/KpiLinkController.ts | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/controllers/KpiLinkController.ts b/src/controllers/KpiLinkController.ts index ca0bdaf..c2ceb7c 100644 --- a/src/controllers/KpiLinkController.ts +++ b/src/controllers/KpiLinkController.ts @@ -124,7 +124,6 @@ export class kpiLinkController extends Controller { await this.positionRepository.remove(chkKpiLink.positions); Object.assign(chkKpiLink, { ...requestBody, - positions: [], kpiCapacitys: [], }); chkKpiLink.kpiGroupId = requestBody.kpiGroupId, @@ -194,22 +193,27 @@ export class kpiLinkController extends Controller { return new HttpSuccess(formattedResponse); } - // /** - // * API ลบเชื่อมโยง - // * @param id - // */ - // @Delete("{id}") - // async deleteKpiLink(@Path() id: string) { - // const kpiLink = await this.kpiLinkRepository.findOne({ - // where: { id: id }, - // }); - // if (!kpiLink) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง"); - // } + /** + * API ลบเชื่อมโยง + * @param id + */ + @Delete("{id}") + async deleteKpiLink(@Path() id: string) { + const kpiLink = await this.kpiLinkRepository.findOne({ + where: { id: id }, + relations: ["kpiCapacitys"], + }); + if (!kpiLink) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง"); + } + kpiLink.kpiCapacitys = []; + await this.kpiLinkRepository.save(kpiLink); - // await this.kpiLinkRepository.remove(kpiLink); - // return new HttpSuccess(); - // } + await this.positionRepository.delete({ kpiLinkId: id }); + await this.kpiLinkRepository.delete({ id: id }); + + return new HttpSuccess(); + } /** * API list เชื่อมโยง