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;