From 7f46b8580953f01e4102673fb4da088acc37a681 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 25 Apr 2024 10:50:38 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B8=AA?= =?UTF-8?q?=E0=B8=A1=E0=B8=A3=E0=B8=A3=E0=B8=96=E0=B8=99=E0=B8=B0=E0=B8=8B?= =?UTF-8?q?=E0=B9=89=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiUserCapacityController.ts | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/controllers/KpiUserCapacityController.ts b/src/controllers/KpiUserCapacityController.ts index 72af22b..3d80fa8 100644 --- a/src/controllers/KpiUserCapacityController.ts +++ b/src/controllers/KpiUserCapacityController.ts @@ -23,7 +23,7 @@ import HttpStatusCode from "../interfaces/http-status"; import { KpiCapacity } from "../entities/kpiCapacity"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; import { KpiUserCapacity, KpiUserCapacityDataPoint} from "../entities/kpiUserCapacity"; -import { Like, In } from "typeorm"; +import { Like, In, Not } from "typeorm"; import { Double } from "typeorm/browser"; @Route("api/v1/kpi/user/capacity") @@ -76,6 +76,18 @@ export class KpiUserCapacityController extends Controller { "ไม่พบข้อมูลรายการสมรรถนะนี้", ); } + const chkRepleat = await this.kpiUserCapacityRepository.find({ + where: { + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiCapacityId: requestBody.kpiCapacityId + } + }) + if(chkRepleat.length > 0){ + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ", + ); + } const kpiUserCapacity = Object.assign(new KpiUserCapacity(), requestBody); kpiUserCapacity.createdUserId = request.user.sub; kpiUserCapacity.createdFullName = request.user.name; @@ -134,6 +146,19 @@ export class KpiUserCapacityController extends Controller { "ไม่พบข้อมูลองค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) นี้", ); } + const chkRepleat = await this.kpiUserCapacityRepository.find({ + where: { + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiCapacityId: requestBody.kpiCapacityId, + id: Not(id) + } + }) + if(chkRepleat.length > 0){ + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถแก้ไขข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ", + ); + } const _kpiUserCapacity = Object.assign(new KpiUserCapacity(), requestBody); kpiUserCapacity.lastUpdateUserId = request.user.sub; kpiUserCapacity.lastUpdateFullName = request.user.name;