validation

This commit is contained in:
AdisakKanthawilang 2024-04-25 11:21:59 +07:00
parent c4950703fc
commit 27794b9031
3 changed files with 65 additions and 0 deletions

View file

@ -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<string, any> },
) {
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;

View file

@ -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;

View file

@ -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);