diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index f296288..d0be283 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -106,9 +106,7 @@ export class KpiUserEvaluationController extends Controller { kpiPeriodId: requestBody.kpiPeriodId, }, ) - .andWhere( - requestBody.year ? "kpiPeriod.year LIKE :year" : "1=1", {year: requestBody.year}, - ) + .andWhere(requestBody.year ? "kpiPeriod.year LIKE :year" : "1=1", { year: requestBody.year }) .andWhere( requestBody.status != null && requestBody.status != undefined ? requestBody.status.trim().toUpperCase() == "NEW" @@ -149,7 +147,7 @@ export class KpiUserEvaluationController extends Controller { ? requestBody.reqedit.trim().toUpperCase() == "NEW" ? `kpiUserEvaluation.evaluationReqEdit LIKE CASE WHEN kpiUserEvaluation.evaluatorId = "${profileId}" THEN "EVALUATOR" WHEN kpiUserEvaluation.commanderId = "${profileId}" THEN "COMMANDER" WHEN kpiUserEvaluation.commanderHighId = "${profileId}" THEN "COMMANDER_HIGH" ELSE "${requestBody.reqedit.trim().toUpperCase()}" END` : "kpiUserEvaluation.evaluationReqEdit LIKE :reqedit" - : "1=1", + : "(kpiUserEvaluation.evaluationReqEdit IS NULL OR kpiUserEvaluation.evaluationReqEdit = 'DONE')", { reqedit: requestBody.reqedit == null || requestBody.reqedit == undefined @@ -207,6 +205,7 @@ export class KpiUserEvaluationController extends Controller { reasonReject: item.reasonReject, actorReject: item.actorReject, actorNameReject: item.actorNameReject, + evaluationReqEdit: item.evaluationReqEdit, isReject: item.reasonReject ? true : false, })); return new HttpSuccess({ data: mapData, total }); @@ -346,21 +345,30 @@ export class KpiUserEvaluationController extends Controller { .orWhere("kpiUserEvaluation.posLevelName LIKE :keyword", { keyword: `%${requestBody.keyword}%`, }) - .orWhere( "kpiUserEvaluation.org LIKE :keyword", { + .orWhere("kpiUserEvaluation.org LIKE :keyword", { keyword: `%${requestBody.keyword}%`, }) - .orWhere( "CONCAT(kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", { - keyword: `%${requestBody.keyword}%`, - }) - .orWhere( "CONCAT(kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", { - keyword: `%${requestBody.keyword}%`, - }) - .orWhere( "CONCAT(kpiUserEvaluation.child3,' ', kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", { - keyword: `%${requestBody.keyword}%`, - }) - .orWhere( "CONCAT(kpiUserEvaluation.child4,' ', kpiUserEvaluation.child3,' ', kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", { + .orWhere("CONCAT(kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", { keyword: `%${requestBody.keyword}%`, }) + .orWhere( + "CONCAT(kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + "CONCAT(kpiUserEvaluation.child3,' ', kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + "CONCAT(kpiUserEvaluation.child4,' ', kpiUserEvaluation.child3,' ', kpiUserEvaluation.child2,' ', kpiUserEvaluation.child1,' ', kpiUserEvaluation.org) LIKE :keyword", + { + keyword: `%${requestBody.keyword}%`, + }, + ) .orWhere(conditionFullName, { keyword: `%${requestBody.keyword}%`, }); @@ -437,12 +445,14 @@ export class KpiUserEvaluationController extends Controller { .createQueryBuilder("kpiUserEvaluation") .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") .andWhere( - requestBody.kpiPeriodId && requestBody.kpiPeriodId != "ALL" ? "kpiUserEvaluation.kpiPeriodId LIKE :kpiPeriodId" : "1=1", + requestBody.kpiPeriodId && requestBody.kpiPeriodId != "ALL" + ? "kpiUserEvaluation.kpiPeriodId LIKE :kpiPeriodId" + : "1=1", { kpiPeriodId: requestBody.kpiPeriodId, }, ) - .andWhere(requestBody.year ? "kpiPeriod.year = :year": "1=1", { year: requestBody.year }) + .andWhere(requestBody.year ? "kpiPeriod.year = :year" : "1=1", { year: requestBody.year }) .andWhere( requestBody.status != null && requestBody.status != undefined ? "kpiUserEvaluation.evaluationstatus LIKE :status" @@ -783,19 +793,43 @@ export class KpiUserEvaluationController extends Controller { }); let levelForGourp: any = null; - if (kpiUserEvaluation.posTypeName == "วิชาการ" && kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ทรงคุณวุฒิ" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "5"; - if (kpiUserEvaluation.posTypeName == "วิชาการ" && kpiUserEvaluation.posLevelName == "เชี่ยวชาญ" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "เชี่ยวชาญ" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "4"; - if (kpiUserEvaluation.posTypeName == "วิชาการ" && kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการพิเศษ" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "4"; - if (kpiUserEvaluation.posTypeName == "วิชาการ" && kpiUserEvaluation.posLevelName == "ชำนาญการ" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ชำนาญการ" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "3"; - if (kpiUserEvaluation.posTypeName == "วิชาการ" && kpiUserEvaluation.posLevelName == "ปฏิบัติการ" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "วิชาการ" && + kpiUserEvaluation.posLevelName == "ปฏิบัติการ" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "2"; if (kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "ทักษะพิเศษ") levelForGourp = "4"; - if (kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "อาวุโส" && kpiUserEvaluation.posExecutiveName == null) + if ( + kpiUserEvaluation.posTypeName == "ทั่วไป" && + kpiUserEvaluation.posLevelName == "อาวุโส" && + kpiUserEvaluation.posExecutiveName == null + ) levelForGourp = "3"; if (kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "ชำนาญงาน") levelForGourp = "2"; @@ -1401,14 +1435,19 @@ export class KpiUserEvaluationController extends Controller { .catch(() => { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); }); - + const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") - .andWhere(kpiPeriodId && kpiPeriodId != "ALL" ? "kpiUserEvaluation.kpiPeriodId LIKE :kpiPeriodId" : "1=1", { - kpiPeriodId: kpiPeriodId, - }) - .andWhere(year ? "kpiPeriod.year = :year": "1=1", { year: year }) + .andWhere( + kpiPeriodId && kpiPeriodId != "ALL" + ? "kpiUserEvaluation.kpiPeriodId LIKE :kpiPeriodId" + : "1=1", + { + kpiPeriodId: kpiPeriodId, + }, + ) + .andWhere(year ? "kpiPeriod.year = :year" : "1=1", { year: year }) .andWhere({ profileId: profileId }) .andWhere( status == null || status == undefined