upd room: status filter for joining table

This commit is contained in:
avicenan
2026-02-19 09:50:52 +07:00
parent cb9fa388d4
commit 8bad4ca68c
2 changed files with 13 additions and 9 deletions

View File

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

View File

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