เพิ่ม where search #776

This commit is contained in:
AdisakKanthawilang 2024-11-12 17:50:04 +07:00
parent da9e89147c
commit 4608ff14de

View file

@ -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)