เพิ่มฟิวผู้บังคับ

This commit is contained in:
Kittapath 2024-04-26 13:08:23 +07:00
parent ba00645cb8
commit ecbb9c0d9f
7 changed files with 171 additions and 64 deletions

View file

@ -24,6 +24,7 @@ import { KpiPeriod } from "../entities/kpiPeriod";
import {
KpiUserEvaluation,
createKpiUserEvaluation,
updateKpiUserCheckEvaluation,
updateKpiUserEvaluation,
} from "../entities/kpiUserEvaluation";
import { Like, In } from "typeorm";
@ -120,6 +121,35 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("check/{id}")
async updateKpiUserCheckEvaluation(
@Path() id: string,
@Body() requestBody: updateKpiUserCheckEvaluation,
@Request() request: { user: Record<string, any> },
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
@ -136,7 +166,7 @@ export class KpiUserEvaluationController extends Controller {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
@ -153,15 +183,13 @@ export class KpiUserEvaluationController extends Controller {
);
}
if (kpiUserEvaluation) {
// kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus
// kpiUserEvaluation.evaluationResults = requestBody.evaluationResults
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
// kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus
// kpiUserEvaluation.evaluationResults = requestBody.evaluationResults
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
@ -173,7 +201,7 @@ export class KpiUserEvaluationController extends Controller {
*/
@Get("{id}")
async GetKpiUserEvaluationById(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
select: [
"id",
@ -187,13 +215,13 @@ export class KpiUserEvaluationController extends Controller {
"createdAt",
],
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
return new HttpSuccess(KpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation);
}
/**
@ -242,16 +270,16 @@ export class KpiUserEvaluationController extends Controller {
*/
@Delete("{id}")
async deleteKpiUserEvaluation(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
await this.kpiUserEvalutionRepository.remove(KpiUserEvaluation);
await this.kpiUserEvalutionRepository.remove(kpiUserEvaluation);
return new HttpSuccess();
}
}