no message

This commit is contained in:
Bright 2024-05-08 16:15:08 +07:00
parent 2b060dedd4
commit bab5532f70
2 changed files with 58 additions and 6 deletions

View file

@ -25,6 +25,7 @@ import {
} from "../entities/kpiUserSpecial";
import HttpError from "../interfaces/http-error";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import { KpiSpecial } from "../entities/kpiSpecial";
import { Not } from "typeorm";
@Route("api/v1/kpi/user/achievement/special")
@ -38,6 +39,7 @@ import { Not } from "typeorm";
export class KpiUserSpecialController extends Controller {
private kpiUserSpecialRepository = AppDataSource.getRepository(KpiUserSpecial);
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
private kpiSpecialRepository = AppDataSource.getRepository(KpiSpecial);
/**
* API
@ -66,18 +68,39 @@ export class KpiUserSpecialController extends Controller {
const chk_indicator = await this.kpiUserSpecialRepository.findOne({
where: {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
including: String(requestBody.including),
includingName: String(requestBody.includingName),
period: requestBody.period,
year: requestBody.year,
},
});
if (
(chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
// (chk_indicator && chk_indicator.including == requestBody.including) ||
// (chk_indicator && chk_indicator.includingName == requestBody.includingName)
chk_indicator
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({
where: {
including: String(requestBody.including),
includingName: String(requestBody.includingName)
},
});
if(!chk_kpiSpecial){
const kpiSpecial = Object.assign(new KpiSpecial(), requestBody);
if (!kpiSpecial) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
kpiSpecial.createdUserId = request.user.sub;
kpiSpecial.createdFullName = request.user.name;
kpiSpecial.lastUpdateUserId = request.user.sub;
kpiSpecial.lastUpdateFullName = request.user.name;
await this.kpiSpecialRepository.save(kpiSpecial);
}
kpiUserSpecial.createdUserId = request.user.sub;
kpiUserSpecial.createdFullName = request.user.name;
kpiUserSpecial.lastUpdateUserId = request.user.sub;
@ -117,18 +140,39 @@ export class KpiUserSpecialController extends Controller {
where: {
id: Not(id),
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
including: String(requestBody.including),
includingName: String(requestBody.includingName),
period: requestBody.period,
year: requestBody.year,
},
});
if (
(chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
// (chk_indicator && chk_indicator.including == requestBody.including) ||
// (chk_indicator && chk_indicator.includingName == requestBody.includingName)
chk_indicator
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({
where: {
including: String(requestBody.including),
includingName: String(requestBody.includingName)
},
});
if(!chk_kpiSpecial){
const kpiSpecial = Object.assign(new KpiSpecial(), requestBody);
if (!kpiSpecial) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
kpiSpecial.createdUserId = request.user.sub;
kpiSpecial.createdFullName = request.user.name;
kpiSpecial.lastUpdateUserId = request.user.sub;
kpiSpecial.lastUpdateFullName = request.user.name;
await this.kpiSpecialRepository.save(kpiSpecial);
}
kpiUserSpecial.lastUpdateUserId = request.user.sub;
kpiUserSpecial.lastUpdateFullName = request.user.name;
kpiUserSpecial.documentInfoEvidence = request.user.documentInfoEvidence;