diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index b6ec9e9..35bd8db 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -69,6 +69,16 @@ export class KpiUserPlannedController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินตามแผน"); } + const chk_indicator = await this.kpiUserPlannedRepository.findOne({ + where: { + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiPlanId: requestBody.kpiPlanId, + }, + }) + if (chk_indicator) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } + const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody); if (!kpiUserPlanned) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); @@ -95,10 +105,22 @@ export class KpiUserPlannedController extends Controller { @Body() requestBody: UpdateKpiUserPlanned, @Request() request: { user: Record }, ) { + const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } }); if (!kpiUserPlanned) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); } + + const chk_indicator = await this.kpiUserPlannedRepository.findOne({ + where: { + id: Not(id), + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiPlanId: requestBody.kpiPlanId, + }, + }) + if (chk_indicator) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } kpiUserPlanned.lastUpdateUserId = request.user.sub; kpiUserPlanned.lastUpdateFullName = request.user.name; diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index ebf4ce3..905d129 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -76,6 +76,16 @@ export class KpiUserRoleController extends Controller { if (!kpiUserRole) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } + + const chk_indicator = await this.kpiUserRoleRepository.findOne({ + where: { + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiRoleId: requestBody.kpiRoleId, + }, + }) + if (chk_indicator) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } kpiUserRole.createdUserId = request.user.sub; kpiUserRole.createdFullName = request.user.name; @@ -118,6 +128,17 @@ export class KpiUserRoleController extends Controller { "ไม่พบข้อมูลแบบประเมินตามหน้าที่ความรับผิดชอบหลัก", ); } + + const chk_indicator = await this.kpiUserRoleRepository.findOne({ + where: { + id: Not(id), + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + kpiRoleId: requestBody.kpiRoleId, + }, + }) + if (chk_indicator) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } kpiUserRole.lastUpdateUserId = request.user.sub; kpiUserRole.lastUpdateFullName = request.user.name; diff --git a/src/controllers/KpiUserSpecialController.ts b/src/controllers/KpiUserSpecialController.ts index 08c918f..a347cb9 100644 --- a/src/controllers/KpiUserSpecialController.ts +++ b/src/controllers/KpiUserSpecialController.ts @@ -25,6 +25,7 @@ import { } from "../entities/kpiUserSpecial"; import HttpError from "../interfaces/http-error"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; +import { Not } from "typeorm"; @Route("api/v1/kpi/user/achievement/special") @Tags("KpiUserSpecial") @@ -62,6 +63,17 @@ export class KpiUserSpecialController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } + + const chk_indicator = await this.kpiUserSpecialRepository.findOne({ + where: { + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + }, + }) + if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } + + kpiUserSpecial.createdUserId = request.user.sub; kpiUserSpecial.createdFullName = request.user.name; kpiUserSpecial.lastUpdateUserId = request.user.sub; @@ -94,6 +106,16 @@ export class KpiUserSpecialController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน"); } + const chk_indicator = await this.kpiUserSpecialRepository.findOne({ + where: { + id: Not(id), + kpiUserEvaluationId: requestBody.kpiUserEvaluationId, + }, + }) + if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { + throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + } + kpiUserSpecial.lastUpdateUserId = request.user.sub; kpiUserSpecial.lastUpdateFullName = request.user.name; Object.assign(kpiUserSpecial, requestBody);