From b95cda95122e21d23bdc35a2fcc58788ddad56e2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 11 Sep 2024 16:55:58 +0700 Subject: [PATCH] split (kpi/evaluation/edit) to criteria --- src/controllers/KpiEvaluationController.ts | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/controllers/KpiEvaluationController.ts b/src/controllers/KpiEvaluationController.ts index 5b5fff1..8b3ad3d 100644 --- a/src/controllers/KpiEvaluationController.ts +++ b/src/controllers/KpiEvaluationController.ts @@ -78,7 +78,41 @@ export class kpiEvaluationController extends Controller { ) { let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY"); let whereClause: any = {}; - console.log("CODE8"); + if (keyword !== undefined && keyword !== "") { + whereClause = { + where: [{ description: Like(`%${keyword}%`) }], + }; + whereClause.where.push({ level: Like(`%${keyword}%`) }); + } + + const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({ + ...whereClause, + ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), + order: { + level: "DESC", + }, + }); + + const formatted = kpiEvaluation.map((item) => ({ + id: item.id, + level: item.level, + description: item.description, + })); + return new HttpSuccess({ data: formatted, total }); + } + + /** + * API เกณฑ์การประเมินในเมนูรายการการประเมิน + */ + @Get("criteria") + async listKpiEvaluationEditInKpiList( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + ) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); + let whereClause: any = {}; if (keyword !== undefined && keyword !== "") { whereClause = { where: [{ description: Like(`%${keyword}%`) }],