From 5db5f445c817965c3513cefc1fb1c507baa3ab4a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 23 Apr 2024 17:06:16 +0700 Subject: [PATCH] point --- src/controllers/KpiUserPlannedController.ts | 30 ++++++++++++++++++++- src/controllers/KpiUserRoleController.ts | 30 ++++++++++++++++++++- src/entities/kpiUserPlanned.ts | 5 ++++ src/entities/kpiUserRole.ts | 7 ++++- 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index 7a6c876..93de3f7 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -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 }, + ){ + + 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(); + } } diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index e45acef..0e3ed12 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -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 }, + ){ + + 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(); + } } diff --git a/src/entities/kpiUserPlanned.ts b/src/entities/kpiUserPlanned.ts index 9060ac7..6cb1736 100644 --- a/src/entities/kpiUserPlanned.ts +++ b/src/entities/kpiUserPlanned.ts @@ -113,3 +113,8 @@ export class UpdateKpiUserPlanned { @Column("uuid") kpiPlanId: string; } + +export class KpiUserPlannedDataPoint { + id: string; + point: number; +} diff --git a/src/entities/kpiUserRole.ts b/src/entities/kpiUserRole.ts index 41e4a94..620e3ca 100644 --- a/src/entities/kpiUserRole.ts +++ b/src/entities/kpiUserRole.ts @@ -115,4 +115,9 @@ export class UpdateKpiUserRole { kpiUserEvaluationId: string; @Column("uuid") kpiRoleId: string; -} \ No newline at end of file +} + +export class KpiUserRoleDataPoint { + id: string; + point: number; +}