upd room: status filter for joining table
This commit is contained in:
@ -199,7 +199,7 @@ export default class CommonHelper {
|
|||||||
return { whereAttr, whereVal };
|
return { whereAttr, whereVal };
|
||||||
}
|
}
|
||||||
|
|
||||||
static handleQueryFilter(filter: { [x: string]: any }): any {
|
static handleQueryFilter(filter: { [x: string]: any }, tableAlias?: string): any {
|
||||||
const whereAttr = [];
|
const whereAttr = [];
|
||||||
const whereVal: any = {};
|
const whereVal: any = {};
|
||||||
|
|
||||||
@ -207,9 +207,12 @@ export default class CommonHelper {
|
|||||||
let f = Array.isArray(filter[p]) ? filter[p] : String(filter[p]);
|
let f = Array.isArray(filter[p]) ? filter[p] : String(filter[p]);
|
||||||
|
|
||||||
if (p !== "any") {
|
if (p !== "any") {
|
||||||
|
const columnName = p.includes(".") ? p : (tableAlias ? `${tableAlias}.${p}` : p);
|
||||||
|
|
||||||
if (!validate(f)) {
|
if (!validate(f)) {
|
||||||
if (p.endsWith("_from") || p.endsWith("_to")) {
|
if (p.endsWith("_from") || p.endsWith("_to")) {
|
||||||
const baseField = p.replace(/_(from|to)$/, "");
|
const baseField = p.replace(/_(from|to)$/, "");
|
||||||
|
const qualifiedBaseField = baseField.includes(".") ? baseField : (tableAlias ? `${tableAlias}.${baseField}` : baseField);
|
||||||
const fromKey = `${baseField}_from`;
|
const fromKey = `${baseField}_from`;
|
||||||
const toKey = `${baseField}_to`;
|
const toKey = `${baseField}_to`;
|
||||||
|
|
||||||
@ -218,19 +221,19 @@ export default class CommonHelper {
|
|||||||
f = filter[p];
|
f = filter[p];
|
||||||
}
|
}
|
||||||
|
|
||||||
whereAttr.push(`${baseField} BETWEEN :_${fromKey} AND :_${toKey}`);
|
whereAttr.push(`${qualifiedBaseField} BETWEEN :_${fromKey} AND :_${toKey}`);
|
||||||
} else if (f === "null") {
|
} else if (f === "null") {
|
||||||
whereAttr.push(`${p} IS NULL`);
|
whereAttr.push(`${columnName} IS NULL`);
|
||||||
} else if (typeof f === "string" && f.includes("%")) {
|
} else if (typeof f === "string" && f.includes("%")) {
|
||||||
whereAttr.push(`${p} ILIKE :_${p}`);
|
whereAttr.push(`${columnName} ILIKE :_${p}`);
|
||||||
whereVal[`_${p}`] = p;
|
whereVal[`_${p}`] = p;
|
||||||
} else if (Array.isArray(f)) {
|
} else if (Array.isArray(f)) {
|
||||||
whereAttr.push(`${p} IN (:..._${p})`);
|
whereAttr.push(`${columnName} IN (:..._${p})`);
|
||||||
} else {
|
} else {
|
||||||
whereAttr.push(`${p} = :_${p}`);
|
whereAttr.push(`${columnName} = :_${p}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
whereAttr.push(`${p} = :_${p}`);
|
whereAttr.push(`${columnName} = :_${p}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
whereVal[`_${p}`] = f;
|
whereVal[`_${p}`] = f;
|
||||||
|
|||||||
@ -9,8 +9,9 @@ export class RoomModel {
|
|||||||
let whereAttr = [];
|
let whereAttr = [];
|
||||||
let whereVal: any = {};
|
let whereVal: any = {};
|
||||||
if (filter) {
|
if (filter) {
|
||||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr];
|
const filterResult = CommonHelper.handleQueryFilter(filter, "Room");
|
||||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal };
|
whereAttr = [...whereAttr, ...filterResult.whereAttr];
|
||||||
|
whereVal = { ...whereVal, ...filterResult.whereVal };
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = null;
|
var query = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user