From 4608ff14de1a67d8c27b987a80f4fb0accd6c57f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 12 Nov 2024 17:50:04 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20where=20search=20#776?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandSalaryController.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/controllers/CommandSalaryController.ts b/src/controllers/CommandSalaryController.ts index bf426436..131a5a70 100644 --- a/src/controllers/CommandSalaryController.ts +++ b/src/controllers/CommandSalaryController.ts @@ -19,6 +19,7 @@ import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { CommandSalary, CreateCommandSalary, UpdateCommandSalary } from "../entities/CommandSalary"; import { CommandSys } from "../entities/CommandSys"; +import { Brackets } from "typeorm"; @Route("api/v1/org/commandSalary") @Tags("CommandSalary") @@ -67,6 +68,7 @@ export class CommandSalaryController extends Controller { @Query("pageSize") pageSize: number = 10, @Query() commandSysId?: string | null, @Query() isActive?: boolean | null, + @Query() searchKeyword?: string | null, ) { const [commandSalarys, total] = await this.commandSalaryRepository .createQueryBuilder("commandSalary") @@ -88,6 +90,18 @@ export class CommandSalaryController extends Controller { : `${commandSysId}`, }, ) + .andWhere( + new Brackets((qb) => { + qb.where( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? "name LIKE :keyword" + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ) + }), + ) .orderBy("commandSalary.createdAt", "ASC") .skip((page - 1) * pageSize) .take(pageSize)