fix: search any in doctor fav item

This commit is contained in:
avicenan
2026-03-17 12:08:07 +07:00
parent 7cb89e7693
commit 1eb3024820

View File

@ -37,19 +37,39 @@ export class DoctorItemController {
}); });
let param: any = await schema.validateAsync(req.query); let param: any = await schema.validateAsync(req.query);
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {}; let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
let filterAny = filter.any && filter.any !== "" ? filter.any : "";
let filterObj = { ...filter } as any;
delete filterObj.any;
// filterObj = { ...filterObj};
const repo = OrmHelper.DB.getRepository(ItemMaster); const repo = OrmHelper.DB.getRepository(ItemMaster);
let whereAttr: string[] = []; let whereAttr: string[] = [];
let whereVal: any = {}; let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) { if (filterObj && Object.keys(filterObj).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter, "item_master"); const filterResult = CommonHelper.handleQueryFilter(filterObj, "item_master");
whereAttr = [...whereAttr, ...filterResult.whereAttr]; whereAttr = [...whereAttr, ...filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal }; whereVal = { ...whereVal, ...filterResult.whereVal };
} }
if (filterAny && filterAny !== "" && filterAny !== null && filterAny !== undefined) {
const filterResult = CommonHelper.handleFilter({
filter: JSON.stringify({ any: filterAny.toLowerCase() }),
col_any_eq: [],
col_any_like: ["item_name", "generic_name"],
});
if (filterResult.whereAttr && filterResult.whereAttr !== "") {
whereAttr = [...whereAttr, filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal };
}
}
const orderField = param.order_field || "id"; const orderField = param.order_field || "id";
const orderDirection = param.order_direction || "asc"; const orderDirection = param.order_direction || "asc";