upd room: status filter for joining table
This commit is contained in:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user