This commit is contained in:
AdisakKanthawilang 2024-04-23 17:06:16 +07:00
parent bdd2c9aa30
commit 5db5f445c8
4 changed files with 69 additions and 3 deletions

View file

@ -19,7 +19,7 @@ import {
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned } from "../entities/kpiUserPlanned";
import { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned, KpiUserPlannedDataPoint } from "../entities/kpiUserPlanned";
import HttpError from "../interfaces/http-error";
import { Not } from "typeorm";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
@ -194,4 +194,32 @@ export class KpiUserPlannedController extends Controller {
}));
return new HttpSuccess(mapKpiUserPlanned);
}
/**
* API
*
* @summary
*
*
*/
@Post("point")
async CreateKpiUserPlannedPoint(
@Body() requestBody: KpiUserPlannedDataPoint[],
@Request() request: { user: Record<string, any> },
){
for (const item of requestBody) {
const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({
where: { id: item.id },
});
if (!kpiUserPlanned) {
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้: ${item.id}`);
}
this.kpiUserPlannedRepository.merge(kpiUserPlanned, item);
kpiUserPlanned.lastUpdateUserId = request.user.sub;
kpiUserPlanned.lastUpdateFullName = request.user.name;
await this.kpiUserPlannedRepository.save(kpiUserPlanned);
}
return new HttpSuccess();
}
}