From 7e3d1856aa0d02ff853eeb61b410dfc9cfe9b61e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 19 Feb 2025 16:32:43 +0700 Subject: [PATCH] #881 --- src/controllers/CommandController.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index f4208e5d..a42342f5 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -224,7 +224,23 @@ export class CommandController extends Controller { .getRawMany(); profilekArray = profiles.map((p) => p.keycloak); } - + //only search command name + let baseKeyword = keyword; + let yearKeyword = ""; + const regex = /\/(\d{4})$/; + const match = keyword.match(regex); + if (match) { + baseKeyword = keyword.substring(0, keyword.lastIndexOf('/')).trim(); + yearKeyword = match[1].trim(); + } + let yearInBC = yearKeyword ? (parseInt(yearKeyword) - 543) : null; + // + + // console.log("k>>",keyword); + // console.log("bk>>",baseKeyword); + // console.log("yk>>",yearKeyword); + // console.log("yi>>",yearInBC); + const [commands, total] = await this.commandRepository .createQueryBuilder("command") .andWhere( @@ -276,8 +292,8 @@ export class CommandController extends Controller { ) .andWhere( new Brackets((qb) => { - qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :baseKeyword" : "1=1", { + baseKeyword: `%${baseKeyword}%`, }) .orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", { keyword: `%${keyword}%`,