diff --git a/src/controllers/doctor_item.ts b/src/controllers/doctor_item.ts index 86b5d39..fd75578 100644 --- a/src/controllers/doctor_item.ts +++ b/src/controllers/doctor_item.ts @@ -37,19 +37,39 @@ 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) { - const filterResult = CommonHelper.handleQueryFilter(filter, "item_master"); + if (filterObj && Object.keys(filterObj).length > 0) { + const filterResult = CommonHelper.handleQueryFilter(filterObj, "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";