diff --git a/src/controllers/KpiLinkController.ts b/src/controllers/KpiLinkController.ts index 4e0035e..72b45b5 100644 --- a/src/controllers/KpiLinkController.ts +++ b/src/controllers/KpiLinkController.ts @@ -136,10 +136,23 @@ export class kpiLinkController extends Controller { ...requestBody, kpiCapacitys: [], }); + + const chkCapacity = await this.kpiCapacityRepository.find({ + where: { + id: In(requestBody.kpiCapacityIds), + }, + }); + if (!chkCapacity) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง"); + } + + chkKpiLink.kpiCapacitys = chkCapacity; chkKpiLink.kpiGroupId = requestBody.kpiGroupId; chkKpiLink.lastUpdateUserId = request.user.sub; chkKpiLink.lastUpdateFullName = request.user.name; chkKpiLink.lastUpdatedAt = new Date(); + await this.kpiLinkRepository.save(chkKpiLink); + setLogDataDiff(request, { before, after: chkKpiLink }); if (requestBody.positions != null) { await Promise.all( @@ -159,19 +172,6 @@ export class kpiLinkController extends Controller { ); } - const chkCapacity = await this.kpiCapacityRepository.find({ - where: { - id: In(requestBody.kpiCapacityIds), - }, - }); - if (!chkCapacity) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง"); - } - chkKpiLink.kpiCapacitys = chkCapacity; - - await this.kpiLinkRepository.save(chkKpiLink, { data: request }); - setLogDataDiff(request, { before, after: chkKpiLink }); - return new HttpSuccess(chkKpiLink.id); }