From 95922c5e73d75c5d70b697c4d113331c58131173 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 15 Jul 2024 15:48:58 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=20kpiDev=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KpiUserDevelopmentController.ts | 140 +++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/src/controllers/KpiUserDevelopmentController.ts b/src/controllers/KpiUserDevelopmentController.ts index ed4336e..b88493c 100644 --- a/src/controllers/KpiUserDevelopmentController.ts +++ b/src/controllers/KpiUserDevelopmentController.ts @@ -25,7 +25,7 @@ import { } from "../entities/kpiUserDevelopment"; import HttpError from "../interfaces/http-error"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; -import { Not, Like } from "typeorm"; +import { Not, Like, Brackets } from "typeorm"; @Route("api/v1/kpi/user/achievement/development") @Tags("KpiUserDevelopment") @@ -262,4 +262,142 @@ export class KpiUserDevelopmentController extends Controller { } return new HttpSuccess(); } + + /** + * API + * + * @summary รายการประเมินผลการปฏิบัติราชการระดับบุคคลทั้งหมด Admin + * + */ + @Post("admin") + async listKpiDevelopmentByStatusKP7( + @Request() request: { user: Record }, + @Body() + requestBody: { + page: number; + pageSize: number; + kpiPeriodId?: string; + keyword?: string; + // status?: string | null; + // results?: string | null; + // reqedit?: string | null; + // evaluating?: boolean | null; + }, + ) { + const [kpiUserDevelopment, total] = await AppDataSource.getRepository(KpiUserDevelopment) + .createQueryBuilder("kpiUserDevelopment") + .leftJoinAndSelect("kpiUserDevelopment.kpiUserEvaluation", "kpiUserEvaluation") + .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") + .where("kpiUserEvaluation.evaluationStatus = :status", { status: "KP7" }) + .andWhere("kpiUserEvaluation.kpiPeriodId = :kpiPeriodId", { + kpiPeriodId: requestBody.kpiPeriodId, + }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.firstName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.lastName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.org LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.position LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.posTypeName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.posLevelName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserDevelopment.name LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .orderBy("kpiUserDevelopment.createdAt", "ASC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + const mapData = kpiUserDevelopment.map((item) => { + const fullNameParts = [ + item.kpiUserEvaluation.child4, + item.kpiUserEvaluation.child3, + item.kpiUserEvaluation.child2, + item.kpiUserEvaluation.child1, + item.kpiUserEvaluation.org, + ]; + + const organization = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join("/"); + + return { + id: item.id, + durationKPI: item.kpiUserEvaluation.kpiPeriod.durationKPI, + developmentName: item.name, + prefix: item.kpiUserEvaluation.prefix ? item.kpiUserEvaluation.prefix : null, + firstname: item.kpiUserEvaluation.firstName ? item.kpiUserEvaluation.firstName : null, + lastname: item.kpiUserEvaluation.lastName ? item.kpiUserEvaluation.lastName : null, + kpiPeriodId: item.kpiUserEvaluation.kpiPeriodId ? item.kpiUserEvaluation.kpiPeriodId : null, + root: item.kpiUserEvaluation.org ? item.kpiUserEvaluation.org : null, + position: item.kpiUserEvaluation.position ? item.kpiUserEvaluation.position : null, + posTypeName: item.kpiUserEvaluation.posTypeName ? item.kpiUserEvaluation.posTypeName : null, + posLevelName: item.kpiUserEvaluation.posLevelName + ? item.kpiUserEvaluation.posLevelName + : null, + organization: organization ? organization : null, + }; + }); + + return new HttpSuccess({ data: mapData, total }); + } + + /** + * API รายการพัฒนาตนเอง Admin + * + * @summary - รายการพัฒนาตนเอง Admin # + * + */ + @Get("admin/detail/{id}") + async GetKpiDevelopmentStatusKP7ById(@Query("id") id: string) { + const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ + relations: [ + "kpiUserEvaluation", + "kpiUserEvaluation.kpiPeriod", + "kpiUserEvaluation.kpiUserCapacitys", + "kpiUserEvaluation.kpiUserCapacitys.kpiCapacity", + ], + where: { + id: id, + }, + }); + + const formattedData = { + id: kpiUserDevelopment?.id ?? null, + evaluationId: kpiUserDevelopment?.kpiUserEvaluation.id ?? null, + target: kpiUserDevelopment?.target ?? null, + summary: kpiUserDevelopment?.summary ?? null, + point: kpiUserDevelopment?.point ?? null, + name: kpiUserDevelopment?.name ?? null, + achievement10: kpiUserDevelopment?.achievement10 ?? null, + achievement5: kpiUserDevelopment?.achievement5 ?? null, + achievement0: kpiUserDevelopment?.achievement0 ?? null, + isDevelopment70: kpiUserDevelopment?.isDevelopment70 ?? null, + isDevelopment20: kpiUserDevelopment?.isDevelopment20 ?? null, + isDevelopment10: kpiUserDevelopment?.isDevelopment10 ?? null, + capacity: + kpiUserDevelopment?.kpiUserEvaluation.kpiUserCapacitys.map((kpiUserCapacity) => ({ + capacityPoint: kpiUserCapacity.point, + capacityName: kpiUserCapacity.kpiCapacity.name, + })) ?? [], + }; + return new HttpSuccess(formattedData); + } }