From a64e20ac23bf9b1a4a1765548ba1e93b5fc68515 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Thu, 18 Apr 2024 13:06:34 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20list=20=E0=B8=81=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiGroupController.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/controllers/KpiGroupController.ts b/src/controllers/KpiGroupController.ts index 39e8fc0..7d0aa85 100644 --- a/src/controllers/KpiGroupController.ts +++ b/src/controllers/KpiGroupController.ts @@ -87,7 +87,6 @@ export class kpiGroupController extends Controller { if (chkkpinameGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว"); } - this.kpiGroupRepository.merge(kpiGroup, requestBody); kpiGroup.lastUpdateUserId = request.user.sub; kpiGroup.lastUpdateFullName = request.user.name; @@ -142,10 +141,16 @@ export class kpiGroupController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { + let whereClause: any = {}; + + if (keyword !== undefined && keyword !== "") { + whereClause = { + where: [{ nameGroupKPI: Like(`%${keyword}%`) }], + }; + } + const [kpiGroup, total] = await this.kpiGroupRepository.findAndCount({ - where: { - nameGroupKPI: Like(`%${keyword}%`), - }, + ...whereClause, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), });