From 7877b591cef207f4eccfd923eb1b13390769a1be Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 13 May 2024 16:19:46 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AD=E0=B8=99=E0=B8=B8=E0=B8=A1=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=20kpi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KpiUserEvaluationController.ts | 185 ++++++++++++++---- 1 file changed, 150 insertions(+), 35 deletions(-) diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 34789d2..90b245a 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -517,6 +517,15 @@ export class KpiUserEvaluationController extends Controller { id: string[]; }, ) { + let profileId: any = null; + await new CallAPI() + .GetData(request, "org/profile/keycloak/position") + .then((x) => { + profileId = x.profileId; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); const list = await this.kpiUserEvalutionRepository.find({ where: { id: In(requestBody.id) }, }); @@ -531,7 +540,35 @@ export class KpiUserEvaluationController extends Controller { } list.forEach(async (item) => { - item.evaluationStatus = requestBody.status.trim().toUpperCase(); + let role = "EVALUATOR"; + if (profileId == item.commanderId) { + role = "COMMANDER"; + } else if (profileId == item.commanderHighId) { + role = "COMMANDERHIGH"; + } + if (requestBody.status.trim().toUpperCase() == "APPROVE") { + if (role == "EVALUATOR") { + if (item.evaluationStatus == "NEW_EVALUATOR") { + if (item.commanderId == null) { + item.evaluationStatus = "APPROVE"; + } else { + item.evaluationStatus = "NEW_COMMANDER"; + } + } + } else if (role == "COMMANDER") { + if (item.evaluationStatus == "NEW_COMMANDER") { + if (item.commanderHighId == null) { + item.evaluationStatus = "APPROVE"; + } else { + item.evaluationStatus = "NEW_COMMANDER_HIGH"; + } + } + } else { + item.evaluationStatus = requestBody.status.trim().toUpperCase(); + } + } else { + item.evaluationStatus = requestBody.status.trim().toUpperCase(); + } item.lastUpdateUserId = request.user.sub; item.lastUpdateFullName = request.user.name; await this.kpiUserEvalutionRepository.save(item); @@ -556,6 +593,16 @@ export class KpiUserEvaluationController extends Controller { id: string[]; }, ) { + let profileId: any = null; + await new CallAPI() + .GetData(request, "org/profile/keycloak/position") + .then((x) => { + profileId = x.profileId; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); + const list = await this.kpiUserEvalutionRepository.find({ where: { id: In(requestBody.id) }, }); @@ -568,9 +615,38 @@ export class KpiUserEvaluationController extends Controller { if (!hasAllData) { throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล"); } - + list.forEach(async (item) => { - item.evaluationReqEdit = requestBody.status.trim().toUpperCase(); + let role = "EVALUATOR"; + if (profileId == item.commanderId) { + role = "COMMANDER"; + } else if (profileId == item.commanderHighId) { + role = "COMMANDERHIGH"; + } + if (requestBody.status.trim().toUpperCase() == "DONE") { + if (role == "EVALUATOR") { + if (item.evaluationReqEdit == "EVALUATOR") { + if (item.commanderId == null) { + item.evaluationReqEdit = "DONE"; + } else { + item.evaluationReqEdit = "COMMANDER"; + } + } + } else if (role == "COMMANDER") { + if (item.evaluationReqEdit == "COMMANDER") { + if (item.commanderHighId == null) { + item.evaluationReqEdit = "DONE"; + } else { + item.evaluationReqEdit = "COMMANDER_HIGH"; + } + } + } else { + item.evaluationReqEdit = requestBody.status.trim().toUpperCase(); + } + } else { + item.evaluationReqEdit = requestBody.status.trim().toUpperCase(); + } + item.lastUpdateUserId = request.user.sub; item.lastUpdateFullName = request.user.name; await this.kpiUserEvalutionRepository.save(item); @@ -579,42 +655,81 @@ export class KpiUserEvaluationController extends Controller { return new HttpSuccess(); } - /** + /** * API แก้ไขสถานะผลการประเมิน * * @summary แก้ไขสถานะผลการประเมิน * * */ - @Post("admin/result-status") - async ResultStatus( - @Request() request: { user: Record }, - @Body() - requestBody: { - status: string; - id: string[]; - }, - ) { - const list = await this.kpiUserEvalutionRepository.find({ - where: { id: In(requestBody.id) }, - }); - if (!list || list.length === 0) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const hasAllData = requestBody.id.every((id) => list.some((item) => item.id === id)); - - if (!hasAllData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล"); - } - - list.forEach(async (item) => { - item.evaluationResults = requestBody.status.trim().toUpperCase(); - item.lastUpdateUserId = request.user.sub; - item.lastUpdateFullName = request.user.name; - await this.kpiUserEvalutionRepository.save(item); - }); - - return new HttpSuccess(); - } + @Post("admin/result-status") + async ResultStatus( + @Request() request: { user: Record }, + @Body() + requestBody: { + status: string; + id: string[]; + }, + ) { + let profileId: any = null; + await new CallAPI() + .GetData(request, "org/profile/keycloak/position") + .then((x) => { + profileId = x.profileId; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); + + const list = await this.kpiUserEvalutionRepository.find({ + where: { id: In(requestBody.id) }, + }); + if (!list || list.length === 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const hasAllData = requestBody.id.every((id) => list.some((item) => item.id === id)); + + if (!hasAllData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล"); + } + + list.forEach(async (item) => { + let role = "EVALUATOR"; + if (profileId == item.commanderId) { + role = "COMMANDER"; + } else if (profileId == item.commanderHighId) { + role = "COMMANDERHIGH"; + } + if (requestBody.status.trim().toUpperCase() == "DONE") { + if (role == "EVALUATOR") { + if (item.evaluationStatus == "EVALUATING_EVALUATOR") { + if (item.commanderId == null) { + item.evaluationStatus = "COMPLETE"; + } else { + item.evaluationStatus = "EVALUATING_COMMANDER"; + } + item.evaluationResults = requestBody.status.trim().toUpperCase(); + } + } else if (role == "COMMANDER") { + if (item.evaluationStatus == "EVALUATING_COMMANDER") { + if (item.commanderHighId == null) { + item.evaluationStatus = "COMPLETE"; + } else { + item.evaluationStatus = "EVALUATING_COMMANDER_HIGH"; + } + } + } else { + item.evaluationStatus = "COMPLETE"; + } + } else { + // item.evaluationStatus = requestBody.status.trim().toUpperCase(); + } + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + await this.kpiUserEvalutionRepository.save(item); + }); + + return new HttpSuccess(); + } }