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();
}
}

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 { KpiUserRole, CreateKpiUserRole, UpdateKpiUserRole } from "../entities/kpiUserRole";
import { KpiUserRole, CreateKpiUserRole, UpdateKpiUserRole, KpiUserRoleDataPoint } from "../entities/kpiUserRole";
import HttpError from "../interfaces/http-error";
import { Not } from "typeorm";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
@ -208,4 +208,32 @@ export class KpiUserRoleController extends Controller {
}));
return new HttpSuccess(mapKpiUserRole);
}
/**
* API
*
* @summary
*
*
*/
@Post("point")
async CreateKpiUserRolePoint(
@Body() requestBody: KpiUserRoleDataPoint[],
@Request() request: { user: Record<string, any> },
){
for (const item of requestBody) {
const kpiUserRole = await this.kpiUserRoleRepository.findOne({
where: { id: item.id },
});
if (!kpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้: ${item.id}`);
}
this.kpiUserRoleRepository.merge(kpiUserRole, item);
kpiUserRole.lastUpdateUserId = request.user.sub;
kpiUserRole.lastUpdateFullName = request.user.name;
await this.kpiUserRoleRepository.save(kpiUserRole);
}
return new HttpSuccess();
}
}

View file

@ -113,3 +113,8 @@ export class UpdateKpiUserPlanned {
@Column("uuid")
kpiPlanId: string;
}
export class KpiUserPlannedDataPoint {
id: string;
point: number;
}

View file

@ -115,4 +115,9 @@ export class UpdateKpiUserRole {
kpiUserEvaluationId: string;
@Column("uuid")
kpiRoleId: string;
}
}
export class KpiUserRoleDataPoint {
id: string;
point: number;
}