From e2bec57f59bd110c970525f2f2faad4ac083c608 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 19 Jun 2024 17:34:31 +0700 Subject: [PATCH] fix --- src/controllers/KpiUserCapacityController.ts | 2 +- .../KpiUserEvaluationController.ts | 284 +++++++++--------- 2 files changed, 143 insertions(+), 143 deletions(-) diff --git a/src/controllers/KpiUserCapacityController.ts b/src/controllers/KpiUserCapacityController.ts index 1a4f312..dd0bc7e 100644 --- a/src/controllers/KpiUserCapacityController.ts +++ b/src/controllers/KpiUserCapacityController.ts @@ -52,7 +52,7 @@ export class KpiUserCapacityController extends Controller { requestBody: { kpiUserEvaluationId: string; kpiCapacityId: string; - level: string; + level: string | null; weight: number; }, @Request() request: { user: Record }, diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index f913473..a085b7b 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -323,153 +323,153 @@ export class KpiUserEvaluationController extends Controller { kpiUserEvaluation.lastUpdateFullName = request.user.name; await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); - // enum CapacityType { - // HEAD = "HEAD", - // GROUP = "GROUP", - // } + enum CapacityType { + HEAD = "HEAD", + GROUP = "GROUP", + } - // // MAIN CAPACITY - // const mainCapacities = await this.kpiCapacityRepository.find({ - // where: { type: CapacityType.HEAD }, - // }); + // MAIN CAPACITY + const mainCapacities = await this.kpiCapacityRepository.find({ + where: { type: CapacityType.HEAD }, + }); - // let level: any; - // switch (level) { - // case kpiUserEvaluation.posTypeName == "บริหาร" && kpiUserEvaluation.posLevelName == "สูง": - // level = 5; - // break; - // case kpiUserEvaluation.posTypeName == "บริหาร" && kpiUserEvaluation.posLevelName == "ต้น": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "อำนวยการ" && kpiUserEvaluation.posLevelName == "สูง": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "อำนวยการ" && kpiUserEvaluation.posLevelName == "ต้น": - // level = 3; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ": - // level = 5; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "เชี่ยวชาญ": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ": - // level = 3; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ชำนาญการ": - // level = 2; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ปฏิบัติการ": - // level = 1; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ทักษะพิเศษ": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "อาวุโส": - // level = 3; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ชำนาญงาน": - // level = 2; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ปฏิบัติงาน": - // level = 1; - // break; - // default: - // level = null; - // break; - // } - // for (const capacity of mainCapacities) { - // await new CallAPI() - // .PostData(request, "kpi/user/capacity", { - // kpiUserEvaluationId: kpiUserEvaluation.id, - // kpiCapacityId: capacity.id, - // level: level, - // weight: 100, - // }) - // .catch((x) => { - // throw new HttpError(HttpStatusCode.NOT_FOUND, x); - // }); - // } + let level: any; + switch (level) { + case kpiUserEvaluation.posTypeName == "บริหาร" && kpiUserEvaluation.posLevelName == "สูง": + level = "5"; + break; + case kpiUserEvaluation.posTypeName == "บริหาร" && kpiUserEvaluation.posLevelName == "ต้น": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "อำนวยการ" && kpiUserEvaluation.posLevelName == "สูง": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "อำนวยการ" && kpiUserEvaluation.posLevelName == "ต้น": + level = "3"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ": + level = "5"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "เชี่ยวชาญ": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ": + level = "3"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการ": + level = "2"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ปฏิบัติการ": + level = "1"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ทักษะพิเศษ": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "อาวุโส": + level = "3"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ชำนาญงาน": + level = "2"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ปฏิบัติงาน": + level = "1"; + break; + default: + level = null; + break; + } + for (const capacity of mainCapacities) { + await new CallAPI() + .PostData(request, "kpi/user/capacity", { + kpiUserEvaluationId: kpiUserEvaluation.id, + kpiCapacityId: capacity.id, + level: level, + weight: 100, + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, x); + }); + } - // // GROUP CAPACITY - // const findPosition = await this.kpiPositionRepository.findOne({ - // where: { name: kpiUserEvaluation.position }, - // }); + // GROUP CAPACITY + const findPosition = await this.kpiPositionRepository.findOne({ + where: { name: kpiUserEvaluation.position }, + }); - // let levelForGourp: any; - // switch (levelForGourp) { - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ": - // level = 5; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "เชี่ยวชาญ": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ชำนาญการ": - // level = 3; - // break; - // case kpiUserEvaluation.posTypeName == "วิชาการ" && - // kpiUserEvaluation.posLevelName == "ปฏิบัติการ": - // level = 2; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ทักษะพิเศษ": - // level = 4; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "อาวุโส": - // level = 3; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ชำนาญงาน": - // level = 2; - // break; - // case kpiUserEvaluation.posTypeName == "ทั่วไป" && - // kpiUserEvaluation.posLevelName == "ปฏิบัติงาน": - // level = 1; - // break; - // default: - // level = null; - // break; - // } + let levelForGourp: any; + switch (levelForGourp) { + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ": + level = "5"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "เชี่ยวชาญ": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการ": + level = "3"; + break; + case kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ปฏิบัติการ": + level = "2"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ทักษะพิเศษ": + level = "4"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "อาวุโส": + level = "3"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ชำนาญงาน": + level = "2"; + break; + case kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "ปฏิบัติงาน": + level = "1"; + break; + default: + level = null; + break; + } - // if (findPosition && findPosition.kpiLinkId && level != null) { - // const findKpiLink = await this.kpiLinkRepository.findOne({ - // relations: ["kpiCapacities"], - // where: { - // id: findPosition.kpiLinkId, - // }, - // }); - // if (findKpiLink) { - // let groupCapacity = findKpiLink.kpiCapacitys; - // for (const capacity of groupCapacity) { - // await new CallAPI() - // .PostData(request, "kpi/user/capacity", { - // kpiUserEvaluationId: kpiUserEvaluation.id, - // kpiCapacityId: capacity.id, - // level: levelForGourp, - // weight: 100, - // }) - // .catch((error) => { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถสร้างข้อมูลสมรรถนะได้"); - // }); - // } - // } - // } + if (findPosition && findPosition.kpiLinkId && level != null) { + const findKpiLink = await this.kpiLinkRepository.findOne({ + relations: ["kpiCapacities"], + where: { + id: findPosition.kpiLinkId, + }, + }); + if (findKpiLink) { + let groupCapacity = findKpiLink.kpiCapacitys; + for (const capacity of groupCapacity) { + await new CallAPI() + .PostData(request, "kpi/user/capacity", { + kpiUserEvaluationId: kpiUserEvaluation.id, + kpiCapacityId: capacity.id, + level: levelForGourp, + weight: 100, + }) + .catch((error) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถสร้างข้อมูลสมรรถนะได้"); + }); + } + } + } return new HttpSuccess(kpiUserEvaluation.id); }