From f12dbfcbeee5cf0b38c34ba17141ddfd693ea499 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 23 Apr 2024 12:29:26 +0700 Subject: [PATCH] checkpoint --- src/controllers/KpiUserPlannedController.ts | 77 +++++++++++---------- src/controllers/KpiUserRoleController.ts | 70 +++++++++---------- src/entities/kpiUserPlanned.ts | 8 +-- 3 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index c7e921d..9c78102 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -119,40 +119,38 @@ export class KpiUserPlannedController extends Controller { return new HttpSuccess(); } - // /** - // * API รายละเอียดงานตามแผนปฏิบัติราชการประจำปี - // * - // * @summary - รายละเอียดงานตามแผนปฏิบัติราชการประจำปี #51 - // * - // * @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี - // */ - // @Get("{id}") - // async GetKpiUserPlannedDetail(@Path() id: string) { - // const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ - // select: ["id", "kpiUserPlannedName", "kpiUserPlannedRank"], - // relations: ["posLevels"], - // where: { id: id }, - // }); - // if (!getKpiUserPlanned) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); - // } + /** + * API รายละเอียดงานตามแผนปฏิบัติราชการประจำปี + * + * @summary - รายละเอียดงานตามแผนปฏิบัติราชการประจำปี #51 + * + * @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี + */ + @Get("{id}") + async GetKpiUserPlannedDetail(@Path() id: string) { + const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ + relations: ["kpiPlan","kpiUserEvaluation"], + where: { id: id }, + }); + if (!getKpiUserPlanned) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); + } - // const mapGetKpiUserPlanned = { - // id: getKpiUserPlanned.id, - // kpiUserPlannedName: getKpiUserPlanned.kpiUserPlannedName, - // kpiUserPlannedRank: getKpiUserPlanned.kpiUserPlannedRank, - // posLevels: getKpiUserPlanned.posLevels - // .sort((a, b) => a.posLevelRank - b.posLevelRank) - // .map((posLevel) => ({ - // id: posLevel.id, - // posLevelName: posLevel.posLevelName, - // posLevelRank: posLevel.posLevelRank, - // posLevelAuthority: posLevel.posLevelAuthority, - // })), - // }; + const mapGetKpiUserPlanned = ({ + id: getKpiUserPlanned.id, + evaluationId: getKpiUserPlanned.kpiUserEvaluation.id, + kpiRoleId: getKpiUserPlanned.kpiPlan.id, + including: getKpiUserPlanned.kpiPlan.including, //รหัสตัวชี้วัด + includingName: getKpiUserPlanned.kpiPlan.includingName, //ชื่อตัวชี้วัด + target: getKpiUserPlanned.target, + weight: getKpiUserPlanned.weight, + unit: getKpiUserPlanned.unit, + meaning: getKpiUserPlanned.meaning, + formula: getKpiUserPlanned.formula, + }); - // return new HttpSuccess(mapGetKpiUserPlanned); - // } + return new HttpSuccess(mapGetKpiUserPlanned); + } /** * API รายการงานตามแผนปฏิบัติราชการประจำปี @@ -161,14 +159,17 @@ export class KpiUserPlannedController extends Controller { * */ @Get() - async GetKpiUserPlanned() { + async GetKpiUserPlanned( + @Query("id") id: string , + ) { const kpiUserPlanned = await this.kpiUserPlannedRepository.find({ + where:{ + kpiUserEvaluationId:id + }, relations: ["kpiPlan","kpiUserEvaluation"], order: { createdAt: "ASC" }, }); - // if (!kpiUserPlanned) { - // return new HttpSuccess([]); - // } + const mapKpiUserPlanned = kpiUserPlanned.map((item) => ({ id: item.id, evaluationId: item.kpiUserEvaluation.id, @@ -183,8 +184,8 @@ export class KpiUserPlannedController extends Controller { achievement: item.point === 1 ? "ระดับ 1" : item.point === 2 ? "ระดับ 2" : item.point === 3 ? "ระดับ 3" : - item.point === 3 ? "ระดับ 4" : - item.point === 3 ? "ระดับ 5" : null, + item.point === 4 ? "ระดับ 4" : + item.point === 5 ? "ระดับ 5" : null, achievement1: item.kpiPlan.achievement1, achievement2: item.kpiPlan.achievement2, achievement3: item.kpiPlan.achievement3, diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index 2ebc912..e45acef 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -132,40 +132,38 @@ export class KpiUserRoleController extends Controller { return new HttpSuccess(); } - // /** - // * API รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก - // * - // * @summary - รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก #51 - // * - // * @param {string} id Id งานตามหน้าที่ความรับผิดชอบหลัก - // */ - // @Get("{id}") - // async GetKpiUserRoleDetail(@Path() id: string) { - // const getKpiUserRole = await this.kpiUserRoleRepository.findOne({ - // select: ["id", "kpiUserRoleName", "kpiUserRoleRank"], - // relations: ["posLevels"], - // where: { id: id }, - // }); - // if (!getKpiUserRole) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้"); - // } + /** + * API รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก + * + * @summary - รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก #51 + * + * @param {string} id Id งานตามหน้าที่ความรับผิดชอบหลัก + */ + @Get("{id}") + async GetKpiUserRoleDetail(@Path() id: string) { + const getKpiUserRole = await this.kpiUserRoleRepository.findOne({ + relations: ["kpiRole","kpiUserEvaluation"], + where: { id: id }, + }); + if (!getKpiUserRole) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้"); + } - // const mapGetKpiUserRole = { - // id: getKpiUserRole.id, - // kpiUserRoleName: getKpiUserRole.kpiUserRoleName, - // kpiUserRoleRank: getKpiUserRole.kpiUserRoleRank, - // posLevels: getKpiUserRole.posLevels - // .sort((a, b) => a.posLevelRank - b.posLevelRank) - // .map((posLevel) => ({ - // id: posLevel.id, - // posLevelName: posLevel.posLevelName, - // posLevelRank: posLevel.posLevelRank, - // posLevelAuthority: posLevel.posLevelAuthority, - // })), - // }; + const mapKpiUserRole = ({ + id: getKpiUserRole.id, + evaluationId: getKpiUserRole.kpiUserEvaluation.id, + kpiRoleId: getKpiUserRole.kpiRole.id, + including: getKpiUserRole.kpiRole.including, + includingName: getKpiUserRole.kpiRole.includingName, + target: getKpiUserRole.target, + weight: getKpiUserRole.weight, + unit: getKpiUserRole.unit, + meaning: getKpiUserRole.meaning, + formula: getKpiUserRole.formula, + }); - // return new HttpSuccess(mapGetKpiUserRole); - // } + return new HttpSuccess(mapKpiUserRole); + } /** * API รายการงานตามหน้าที่ความรับผิดชอบหลัก @@ -184,9 +182,7 @@ export class KpiUserRoleController extends Controller { relations: ["kpiRole","kpiUserEvaluation"], order: { createdAt: "ASC" }, }); - // if (!kpiUserRole) { - // return new HttpSuccess([]); - // } + const mapKpiUserRole = kpiUserRole.map((item) => ({ id: item.id, evaluationId: item.kpiUserEvaluation.id, @@ -202,8 +198,8 @@ export class KpiUserRoleController extends Controller { achievement: item.point === 1 ? "ระดับ 1" : item.point === 2 ? "ระดับ 2" : item.point === 3 ? "ระดับ 3" : - item.point === 3 ? "ระดับ 4" : - item.point === 3 ? "ระดับ 5" : null, + item.point === 4 ? "ระดับ 4" : + item.point === 5 ? "ระดับ 5" : null, achievement1: item.kpiRole.achievement1, achievement2: item.kpiRole.achievement2, achievement3: item.kpiRole.achievement3, diff --git a/src/entities/kpiUserPlanned.ts b/src/entities/kpiUserPlanned.ts index 065c4da..9060ac7 100644 --- a/src/entities/kpiUserPlanned.ts +++ b/src/entities/kpiUserPlanned.ts @@ -108,8 +108,8 @@ export class UpdateKpiUserPlanned { meaning: string; @Column() formula: string; - // @Column("uuid") - // kpiUserEvaluationId: string; - // @Column("uuid") - // kpiPlanId: string; + @Column("uuid") + kpiUserEvaluationId: string; + @Column("uuid") + kpiPlanId: string; }