validation
This commit is contained in:
parent
c4950703fc
commit
27794b9031
3 changed files with 65 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue