From 8bad4ca68cbc2450a734254ad5f85e9dcbc926d0 Mon Sep 17 00:00:00 2001 From: avicenan Date: Thu, 19 Feb 2026 09:50:52 +0700 Subject: [PATCH] upd room: status filter for joining table --- src/helpers/common.ts | 17 ++++++++++------- src/model/room.ts | 5 +++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/helpers/common.ts b/src/helpers/common.ts index 55be161..e2a5a60 100644 --- a/src/helpers/common.ts +++ b/src/helpers/common.ts @@ -199,7 +199,7 @@ export default class CommonHelper { return { whereAttr, whereVal }; } - static handleQueryFilter(filter: { [x: string]: any }): any { + static handleQueryFilter(filter: { [x: string]: any }, tableAlias?: string): any { const whereAttr = []; const whereVal: any = {}; @@ -207,9 +207,12 @@ export default class CommonHelper { let f = Array.isArray(filter[p]) ? filter[p] : String(filter[p]); if (p !== "any") { + const columnName = p.includes(".") ? p : (tableAlias ? `${tableAlias}.${p}` : p); + if (!validate(f)) { if (p.endsWith("_from") || p.endsWith("_to")) { const baseField = p.replace(/_(from|to)$/, ""); + const qualifiedBaseField = baseField.includes(".") ? baseField : (tableAlias ? `${tableAlias}.${baseField}` : baseField); const fromKey = `${baseField}_from`; const toKey = `${baseField}_to`; @@ -218,19 +221,19 @@ export default class CommonHelper { f = filter[p]; } - whereAttr.push(`${baseField} BETWEEN :_${fromKey} AND :_${toKey}`); + whereAttr.push(`${qualifiedBaseField} BETWEEN :_${fromKey} AND :_${toKey}`); } else if (f === "null") { - whereAttr.push(`${p} IS NULL`); + whereAttr.push(`${columnName} IS NULL`); } else if (typeof f === "string" && f.includes("%")) { - whereAttr.push(`${p} ILIKE :_${p}`); + whereAttr.push(`${columnName} ILIKE :_${p}`); whereVal[`_${p}`] = p; } else if (Array.isArray(f)) { - whereAttr.push(`${p} IN (:..._${p})`); + whereAttr.push(`${columnName} IN (:..._${p})`); } else { - whereAttr.push(`${p} = :_${p}`); + whereAttr.push(`${columnName} = :_${p}`); } } else { - whereAttr.push(`${p} = :_${p}`); + whereAttr.push(`${columnName} = :_${p}`); } whereVal[`_${p}`] = f; diff --git a/src/model/room.ts b/src/model/room.ts index 01d68bb..bc35c93 100644 --- a/src/model/room.ts +++ b/src/model/room.ts @@ -9,8 +9,9 @@ export class RoomModel { let whereAttr = []; let whereVal: any = {}; if (filter) { - whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr]; - whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal }; + const filterResult = CommonHelper.handleQueryFilter(filter, "Room"); + whereAttr = [...whereAttr, ...filterResult.whereAttr]; + whereVal = { ...whereVal, ...filterResult.whereVal }; } var query = null;