From 5578bd4f18f02d115ad3904b9ac35ce0bc341a57 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Thu, 18 Apr 2024 12:16:31 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=81=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiGroupController.ts | 20 ++++++++------------ src/controllers/KpiPeriodController.ts | 7 ++++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/controllers/KpiGroupController.ts b/src/controllers/KpiGroupController.ts index a59ec34..39e8fc0 100644 --- a/src/controllers/KpiGroupController.ts +++ b/src/controllers/KpiGroupController.ts @@ -18,6 +18,7 @@ import { import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; +import { Like, Not } from "typeorm"; import HttpStatusCode from "../interfaces/http-status"; import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGroup"; @Route("api/v1/kpi/group") @@ -34,7 +35,6 @@ export class kpiGroupController extends Controller { /** * API สร้างกลุ่มงาน * @param requestBody - * @param request * @returns */ @Post() @@ -46,12 +46,12 @@ export class kpiGroupController extends Controller { @Request() request: { user: Record }, ) { const kpiGroup = Object.assign(new KpiGroup(), requestBody); - const ChkkpinameGroup = await this.kpiGroupRepository.findOne({ + const chkkpinameGroup = await this.kpiGroupRepository.findOne({ where: { nameGroupKPI: requestBody.nameGroupKPI, }, }); - if (ChkkpinameGroup) { + if (chkkpinameGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว"); } kpiGroup.createdUserId = request.user.sub; @@ -79,16 +79,15 @@ export class kpiGroupController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้"); } - const ChkkpinameGroup = await this.kpiGroupRepository.findOne({ + const chkkpinameGroup = await this.kpiGroupRepository.findOne({ where: { nameGroupKPI: requestBody.nameGroupKPI, }, }); - if (ChkkpinameGroup) { + if (chkkpinameGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว"); } - requestBody.nameGroupKPI = requestBody.nameGroupKPI; this.kpiGroupRepository.merge(kpiGroup, requestBody); kpiGroup.lastUpdateUserId = request.user.sub; kpiGroup.lastUpdateFullName = request.user.name; @@ -136,20 +135,17 @@ export class kpiGroupController extends Controller { * API list กลุ่มงาน * @param page * @param pageSize - * @param year - * @param keyword */ @Get() async listKpiGroup( @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, - @Query("year") year?: string, @Query("keyword") keyword?: string, ) { const [kpiGroup, total] = await this.kpiGroupRepository.findAndCount({ - // where: { - // name: Like(`%${keyword}%`), - // }, + where: { + nameGroupKPI: Like(`%${keyword}%`), + }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), }); diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index d580399..6bcb8b2 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -20,6 +20,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpiPeriod"; +import { Like } from "typeorm/browser"; @Route("api/v1/kpi/period") @Tags("kpiPeriod") @@ -176,9 +177,9 @@ export class kpiController extends Controller { @Query("keyword") keyword?: string, ) { const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({ - // where: { - // name: Like(`%${keyword}%`), - // }, + // where: { + // durationKPI: Like(`%${keyword}%`), + // }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), });