fix search doctor item

This commit is contained in:
avicenan
2026-03-17 13:02:48 +07:00
parent 1eb3024820
commit 7d00506e93

View File

@ -159,19 +159,38 @@ export class DoctorItemController {
});
let param: any = await schema.validateAsync(req.query);
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);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
if (filterObj && Object.keys(filterObj).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter, "item_master");
whereAttr = [...whereAttr, ...filterResult.whereAttr];
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 orderDirection = param.order_direction || "asc";