feat(api): add keyword filter for guarantor list
Parse `filter.any` separately from structured filters and pass it to the model query so generic search can match guarantor name and phone.
This commit is contained in:
@ -4,13 +4,26 @@ import { OrmHelper } from "../helpers/orm";
|
||||
import { PatientGuarantor } from "entity";
|
||||
|
||||
export class PatientGuarantorModel {
|
||||
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
|
||||
static async list(filterObj = {}, filterAny: string = ""): Promise<SelectQueryBuilder<any>> {
|
||||
const repo = OrmHelper.DB.getRepository(PatientGuarantor);
|
||||
let whereAttr: string[] = [];
|
||||
let whereVal: any = {};
|
||||
if (filter && Object.keys(filter).length > 0) {
|
||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "patient_guarantor").whereAttr];
|
||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "patient_guarantor").whereVal };
|
||||
if (filterObj && Object.keys(filterObj).length > 0) {
|
||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filterObj, "patient_guarantor").whereAttr];
|
||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filterObj, "patient_guarantor").whereVal };
|
||||
}
|
||||
|
||||
if (filterAny && filterAny !== "" && filterAny !== null && filterAny !== undefined) {
|
||||
const filterResult = CommonHelper.handleFilter({
|
||||
filter: JSON.stringify({ any: filterAny }),
|
||||
col_any_eq: [],
|
||||
col_any_like: ["name", "phone"],
|
||||
});
|
||||
|
||||
if (filterResult.whereAttr && filterResult.whereAttr !== "") {
|
||||
whereAttr = [...whereAttr, filterResult.whereAttr];
|
||||
whereVal = { ...whereVal, ...filterResult.whereVal };
|
||||
}
|
||||
}
|
||||
|
||||
var query = repo.createQueryBuilder("patient_guarantor").leftJoinAndSelect("patient_guarantor.patient_group", "patient_group");
|
||||
|
||||
Reference in New Issue
Block a user