From 245e7f9df55aa53d557fab4fba5e9c3a4c30b40e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 22 Apr 2024 17:10:37 +0700 Subject: [PATCH] fix --- .../KpiUserEvaluationController.ts | 8 +- src/controllers/KpiUserPlannedController.ts | 234 ++++++++++++++++++ src/entities/kpiUserEvaluation.ts | 16 +- 3 files changed, 242 insertions(+), 16 deletions(-) create mode 100644 src/controllers/KpiUserPlannedController.ts diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 1d76b27..0b5eea2 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -69,8 +69,8 @@ export class KpiUserEvaluationController extends Controller { kpiUserEvaluation.lastName = x.lastName }) .catch((x) => {}); - kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus - kpiUserEvaluation.evaluationResults = requestBody.evaluationResults + kpiUserEvaluation.evaluationStatus = "PENDING"; + kpiUserEvaluation.evaluationResults = "PENDING"; kpiUserEvaluation.createdUserId = request.user.sub; kpiUserEvaluation.createdFullName = request.user.name; kpiUserEvaluation.lastUpdateUserId = request.user.sub; @@ -113,8 +113,8 @@ export class KpiUserEvaluationController extends Controller { } if (kpiUserEvaluation) { - kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus - kpiUserEvaluation.evaluationResults = requestBody.evaluationResults + // kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus + // kpiUserEvaluation.evaluationResults = requestBody.evaluationResults kpiUserEvaluation.lastUpdateUserId = request.user.sub; kpiUserEvaluation.lastUpdateFullName = request.user.name; this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody); diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts new file mode 100644 index 0000000..f49225c --- /dev/null +++ b/src/controllers/KpiUserPlannedController.ts @@ -0,0 +1,234 @@ +// import { +// Controller, +// Get, +// Post, +// Put, +// Delete, +// Patch, +// Route, +// Security, +// Tags, +// Body, +// Path, +// Request, +// Example, +// SuccessResponse, +// Response, +// Query, +// } from "tsoa"; +// 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 HttpError from "../interfaces/http-error"; +// import { Not } from "typeorm"; + +// @Route("api/v1/kpi/user/achievement/planned") +// @Tags("KpiUserPlanned") +// @Security("bearerAuth") +// @Response( +// HttpStatusCode.INTERNAL_SERVER_ERROR, +// "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +// ) +// @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +// export class KpiUserPlannedController extends Controller { +// private posTypeRepository = AppDataSource.getRepository(KpiUserPlanned); +// private posLevelRepository = AppDataSource.getRepository(PosLevel); + +// /** +// * API เพิ่มประเภทตำแหน่ง +// * +// * @summary ORG_045 - เพิ่มประเภทตำแหน่ง (ADMIN) #48 +// * +// */ +// @Post() +// @Example({ +// positionName: "นักบริหาร", +// posTypeRank: 1, +// }) +// async createType( +// @Body() +// requestBody: CreateKpiUserPlanned, +// @Request() request: { user: Record }, +// ) { +// const posType = Object.assign(new KpiUserPlanned(), requestBody); +// if (!posType) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); +// } +// const chkKpiUserPlannedName = await this.posTypeRepository.findOne({ +// where: { +// posTypeName: requestBody.posTypeName, +// }, +// }); +// if (chkKpiUserPlannedName) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว"); +// } +// posType.createdUserId = request.user.sub; +// posType.createdFullName = request.user.name; +// posType.lastUpdateUserId = request.user.sub; +// posType.lastUpdateFullName = request.user.name; +// await this.posTypeRepository.save(posType); +// return new HttpSuccess(posType); +// } + +// /** +// * API แก้ไขประเภทตำแหน่ง +// * +// * @summary ORG_046 - แก้ไขประเภทตำแหน่ง (ADMIN) #49 +// * +// * @param {string} id Id ประเภทตำแหน่ง +// */ +// @Put("{id}") +// @Example({ +// positionName: "นักบริหาร", +// posTypeRank: 1, +// }) +// async editType( +// @Path() id: string, +// @Body() requestBody: UpdateKpiUserPlanned, +// @Request() request: { user: Record }, +// ) { +// const posType = await this.posTypeRepository.findOne({ where: { id } }); +// if (!posType) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); +// } +// const chkKpiUserPlannedName = await this.posTypeRepository.findOne({ +// where: { +// id: Not(id), +// posTypeName: requestBody.posTypeName, +// }, +// }); +// if (chkKpiUserPlannedName) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว"); +// } +// posType.lastUpdateUserId = request.user.sub; +// posType.lastUpdateFullName = request.user.name; +// this.posTypeRepository.merge(posType, requestBody); +// await this.posTypeRepository.save(posType); +// return new HttpSuccess(posType.id); +// } + +// /** +// * API ลบประเภทตำแหน่ง +// * +// * @summary ORG_047 - ลบประเภทตำแหน่ง (ADMIN) #50 +// * +// * @param {string} id Id ตำแหน่ง +// */ +// @Delete("{id}") +// async deleteType(@Path() id: string) { +// const delKpiUserPlanned = await this.posTypeRepository.findOne({ where: { id } }); +// if (!delKpiUserPlanned) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); +// } +// const IdExitsInLevel = await this.posLevelRepository.find({ +// where: { posTypeId: id }, +// }); +// if (IdExitsInLevel.length > 0) { +// throw new HttpError( +// HttpStatusCode.NOT_FOUND, +// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับตำแหน่ง", +// ); +// } + +// await this.posTypeRepository.remove(delKpiUserPlanned); +// return new HttpSuccess(); +// } + +// /** +// * API รายละเอียดประเภทตำแหน่ง +// * +// * @summary ORG_048 - รายละเอียดประเภทตำแหน่ง (ADMIN) #51 +// * +// * @param {string} id Id ประเภทตำแหน่ง +// */ +// @Get("{id}") +// @Example([ +// { +// id: "00000000-0000-0000-0000-000000000000", +// posTypeName: "นักบริหาร", +// posLevelposTypeRanks: 1, +// posLevels: [ +// { +// id: "00000000-0000-0000-0000-000000000000", +// posLevelName: "นักบริหาร", +// posLevelRank: 1, +// posLevelAuthority: "HEAD", +// }, +// ], +// }, +// ]) +// async GetTypeDetail(@Path() id: string) { +// const getKpiUserPlanned = await this.posTypeRepository.findOne({ +// select: ["id", "posTypeName", "posTypeRank"], +// relations: ["posLevels"], +// where: { id: id }, +// }); +// if (!getKpiUserPlanned) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); +// } + +// const mapGetKpiUserPlanned = { +// id: getKpiUserPlanned.id, +// posTypeName: getKpiUserPlanned.posTypeName, +// posTypeRank: getKpiUserPlanned.posTypeRank, +// posLevels: getKpiUserPlanned.posLevels +// .sort((a, b) => a.posLevelRank - b.posLevelRank) +// .map((posLevel) => ({ +// id: posLevel.id, +// posLevelName: posLevel.posLevelName, +// posLevelRank: posLevel.posLevelRank, +// posLevelAuthority: posLevel.posLevelAuthority, +// })), +// }; + +// return new HttpSuccess(mapGetKpiUserPlanned); +// } + +// /** +// * API รายการประเภทตำแหน่ง +// * +// * @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29 +// * +// */ +// @Get() +// @Example([ +// { +// id: "00000000-0000-0000-0000-000000000000", +// posTypeName: "นักบริหาร", +// posTypeRank: 1, +// posLevels: [ +// { +// id: "00000000-0000-0000-0000-000000000000", +// posLevelName: "นักบริหาร", +// posLevelRank: 1, +// posLevelAuthority: "HEAD", +// }, +// ], +// }, +// ]) +// async GetKpiUserPlanned() { +// const posType = await this.posTypeRepository.find({ +// select: ["id", "posTypeName", "posTypeRank"], +// relations: ["posLevels"], +// order: { posTypeRank: "ASC" }, +// }); +// // if (!posType) { +// // return new HttpSuccess([]); +// // } +// const mapKpiUserPlanned = posType.map((item) => ({ +// id: item.id, +// posTypeName: item.posTypeName, +// posTypeRank: item.posTypeRank, +// posLevels: item.posLevels +// .sort((a, b) => a.posLevelRank - b.posLevelRank) +// .map((posLevel) => ({ +// id: posLevel.id, +// posLevelName: posLevel.posLevelName, +// posLevelRank: posLevel.posLevelRank, +// posLevelAuthority: posLevel.posLevelAuthority, +// })), +// })); +// return new HttpSuccess(mapKpiUserPlanned); +// } +// } diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index f058ed2..05ac3c1 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -48,19 +48,19 @@ export class KpiUserEvaluation extends EntityBase { profileId: string; @Column({ - // PENDING = รอการประเมิน , INPROGRESS = กําลังประเมิน , DONE = ประเมินเสร็จสิ้น + // "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", nullable: true, length: 40, - comment: "สถานะการประเมินผล", + comment: "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", default: null, }) evaluationStatus: string; @Column({ - // PASSED = ผ่านการประเมิน , NOTPASSED = ไม่ผ่านการประเมิน + // "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", nullable: true, length: 40, - comment: "ผลการประเมิน", + comment: "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", default: null, }) evaluationResults: string; @@ -93,10 +93,6 @@ export class createKpiUserEvaluation { kpiPeriodId: string; @Column() profileId: string; - @Column() - evaluationStatus: string; - @Column() - evaluationResults: string; } export class updateKpiUserEvaluation { @@ -110,8 +106,4 @@ export class updateKpiUserEvaluation { kpiPeriodId: string; @Column() profileId: string; - @Column() - evaluationStatus: string; - @Column() - evaluationResults: string; }