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

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