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;