From 4c06594af80c34c64f448e961ea483b21f5bd3a8 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 16 Jan 2025 14:07:29 +0700 Subject: [PATCH] add auery --- src/controllers/KpiPlanController.ts | 12 +++-- .../KpiUserEvaluationController.ts | 4 ++ src/controllers/KpiUserPlannedController.ts | 46 +++++++++++++++---- src/controllers/KpiUserRoleController.ts | 33 +++++++++---- src/entities/kpiUserEvaluation.ts | 7 +++ 5 files changed, 78 insertions(+), 24 deletions(-) diff --git a/src/controllers/KpiPlanController.ts b/src/controllers/KpiPlanController.ts index d21a7ca..59afe58 100644 --- a/src/controllers/KpiPlanController.ts +++ b/src/controllers/KpiPlanController.ts @@ -59,7 +59,10 @@ export class kpiPlanController extends Controller { .where("kpiPeriod.year = :year", { year: requestBody.year }) .andWhere("kpiPeriod.durationKPI = :durationKPI", { durationKPI: requestBody.period }) .getOne(); - const year = requestBody.year && parseInt(requestBody.year) > 0?parseInt(requestBody.year) + 543:"ดังกล่าว"; + const year = + requestBody.year && parseInt(requestBody.year) > 0 + ? parseInt(requestBody.year) + 543 + : "ดังกล่าว"; if (!kpiPeriod) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้"); throw new HttpError( @@ -453,6 +456,7 @@ export class kpiPlanController extends Controller { if (kpiPlan.strategyChild5Id != null) { strategy = 5; strategyId = kpiPlan.strategyChild5Id; + strategyName = kpiPlan.strategyChild5; } else if (kpiPlan.strategyChild4Id != null) { strategy = 4; strategyId = kpiPlan.strategyChild4Id; @@ -870,11 +874,11 @@ export class kpiPlanController extends Controller { type = 4; } - const _null:any = null; + const _null: any = null; await this.kpiPlanHistoryRepository.delete({ kpiPlanId: id }); - await this.kpiUserPlanRepository.update({ kpiPlanId: id },{ kpiPlanId: _null }); + await this.kpiUserPlanRepository.update({ kpiPlanId: id }, { kpiPlanId: _null }); await this.kpiPlanRepository.remove(kpiPlan, { data: request }); - + if (kpiPlan) { let remainingKpiPlans: any; if (type == 0) { diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 68b59ab..9ab95ca 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -526,6 +526,7 @@ export class KpiUserEvaluationController extends Controller { kpiUserEvaluation.posLevelName = x.posLevelName; kpiUserEvaluation.posTypeName = x.posTypeName; kpiUserEvaluation.posExecutiveName = x.posExecutiveName; + kpiUserEvaluation.isProbation = x.isProbation; kpiUserEvaluation.org = x.root; kpiUserEvaluation.orgId = x.rootId; kpiUserEvaluation.child1 = x.child1; @@ -553,6 +554,7 @@ export class KpiUserEvaluationController extends Controller { kpiUserEvaluation.posLevelName = x.posLevelName; kpiUserEvaluation.posTypeName = x.posTypeName; kpiUserEvaluation.posExecutiveName = x.posExecutiveName; + kpiUserEvaluation.isProbation = x.isProbation; kpiUserEvaluation.org = x.root; kpiUserEvaluation.orgId = x.rootId; kpiUserEvaluation.child1 = x.child1; @@ -1058,6 +1060,7 @@ export class KpiUserEvaluationController extends Controller { evaluationStatus: kpiUserEvaluation.evaluationStatus, evaluationResults: kpiUserEvaluation.evaluationResults, evaluationReqEdit: kpiUserEvaluation.evaluationReqEdit, + isProbation: kpiUserEvaluation.isProbation, createdAt: kpiUserEvaluation.createdAt, evaluatorId: kpiUserEvaluation.evaluatorId, commanderId: kpiUserEvaluation.commanderId, @@ -1482,6 +1485,7 @@ export class KpiUserEvaluationController extends Controller { evaluationStatus: kpiUserEvaluation.evaluationStatus, evaluationResults: kpiUserEvaluation.evaluationResults, evaluationReqEdit: kpiUserEvaluation.evaluationReqEdit, + isProbation: kpiUserEvaluation.isProbation, createdAt: kpiUserEvaluation.createdAt, evaluatorId: kpiUserEvaluation.evaluatorId, commanderId: kpiUserEvaluation.commanderId, diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index 9253ed5..50fbfbd 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -198,12 +198,38 @@ export class KpiUserPlannedController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); } + let nodeName = null; + if (getKpiUserPlanned.kpiPlan.child4Id != null) { + nodeName = getKpiUserPlanned.kpiPlan.child4; + } else if (getKpiUserPlanned.kpiPlan.child3Id != null) { + nodeName = getKpiUserPlanned.kpiPlan.child3; + } else if (getKpiUserPlanned.kpiPlan.child2Id != null) { + nodeName = getKpiUserPlanned.kpiPlan.child2; + } else if (getKpiUserPlanned.kpiPlan.child1Id != null) { + nodeName = getKpiUserPlanned.kpiPlan.child1; + } else if (getKpiUserPlanned.kpiPlan.rootId != null) { + nodeName = getKpiUserPlanned.kpiPlan.root; + } + let strategyName = null; + if (getKpiUserPlanned.kpiPlan.strategyChild5Id != null) { + strategyName = getKpiUserPlanned.kpiPlan.strategyChild5; + } else if (getKpiUserPlanned.kpiPlan.strategyChild4Id != null) { + strategyName = getKpiUserPlanned.kpiPlan.strategyChild4; + } else if (getKpiUserPlanned.kpiPlan.strategyChild3Id != null) { + strategyName = getKpiUserPlanned.kpiPlan.strategyChild3; + } else if (getKpiUserPlanned.kpiPlan.strategyChild2Id != null) { + strategyName = getKpiUserPlanned.kpiPlan.strategyChild2; + } else if (getKpiUserPlanned.kpiPlan.strategyChild1Id != null) { + strategyName = getKpiUserPlanned.kpiPlan.strategyChild1; + } const mapGetKpiUserPlanned = { id: getKpiUserPlanned.id, evaluationId: getKpiUserPlanned.kpiUserEvaluation.id, kpiPlanId: getKpiUserPlanned.kpiPlan.id, including: getKpiUserPlanned.kpiPlan.including, //รหัสตัวชี้วัด includingName: getKpiUserPlanned.kpiPlan.includingName, //ชื่อตัวชี้วัด + nodeName: nodeName, + strategyName: strategyName, target: getKpiUserPlanned.target, weight: getKpiUserPlanned.weight, unit: getKpiUserPlanned.unit, @@ -254,21 +280,21 @@ export class KpiUserPlannedController extends Controller { point: item.point, achievement: item.point === 1 - ? item.kpiPlan.achievement1 + ? item.achievement1 : item.point === 2 - ? item.kpiPlan.achievement2 + ? item.achievement2 : item.point === 3 - ? item.kpiPlan.achievement3 + ? item.achievement3 : item.point === 4 - ? item.kpiPlan.achievement4 + ? item.achievement4 : item.point === 5 - ? item.kpiPlan.achievement5 + ? item.achievement5 : null, - achievement1: item.kpiPlan.achievement1, - achievement2: item.kpiPlan.achievement2, - achievement3: item.kpiPlan.achievement3, - achievement4: item.kpiPlan.achievement4, - achievement5: item.kpiPlan.achievement5, + achievement1: item.achievement1, + achievement2: item.achievement2, + achievement3: item.achievement3, + achievement4: item.achievement4, + achievement5: item.achievement5, })); return new HttpSuccess(mapKpiUserPlanned); } diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index 4de3c2f..9398c28 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -202,12 +202,25 @@ export class KpiUserRoleController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้"); } + let nodeName = null; + if (getKpiUserRole.kpiRole.child4Id != null) { + nodeName = getKpiUserRole.kpiRole.child4; + } else if (getKpiUserRole.kpiRole.child3Id != null) { + nodeName = getKpiUserRole.kpiRole.child3; + } else if (getKpiUserRole.kpiRole.child2Id != null) { + nodeName = getKpiUserRole.kpiRole.child2; + } else if (getKpiUserRole.kpiRole.child1Id != null) { + nodeName = getKpiUserRole.kpiRole.child1; + } else if (getKpiUserRole.kpiRole.rootId != null) { + nodeName = getKpiUserRole.kpiRole.root; + } const mapKpiUserRole = { id: getKpiUserRole.id, evaluationId: getKpiUserRole.kpiUserEvaluation.id, kpiRoleId: getKpiUserRole.kpiRole.id, including: getKpiUserRole.kpiRole.including, includingName: getKpiUserRole.kpiRole.includingName, + nodeName: nodeName, target: getKpiUserRole.target, weight: getKpiUserRole.weight, unit: getKpiUserRole.unit, @@ -259,21 +272,21 @@ export class KpiUserRoleController extends Controller { point: item.point, achievement: item.point === 1 - ? item.kpiRole.achievement1 + ? item.achievement1 : item.point === 2 - ? item.kpiRole.achievement2 + ? item.achievement2 : item.point === 3 - ? item.kpiRole.achievement3 + ? item.achievement3 : item.point === 4 - ? item.kpiRole.achievement4 + ? item.achievement4 : item.point === 5 - ? item.kpiRole.achievement5 + ? item.achievement5 : null, - achievement1: item.kpiRole.achievement1, - achievement2: item.kpiRole.achievement2, - achievement3: item.kpiRole.achievement3, - achievement4: item.kpiRole.achievement4, - achievement5: item.kpiRole.achievement5, + achievement1: item.achievement1, + achievement2: item.achievement2, + achievement3: item.achievement3, + achievement4: item.achievement4, + achievement5: item.achievement5, })); return new HttpSuccess(mapKpiUserRole); } diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index ad6e9bd..14f32d9 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -481,6 +481,13 @@ export class KpiUserEvaluation extends EntityBase { }) isOpen: boolean; + @Column({ + nullable: true, + comment: "สถานะทดลองงาน", + default: false, + }) + isProbation: boolean; + @Column({ nullable: true, type: "datetime",