knex conditional where
const getFilteredItems = (searchCriteria) => knex('items')
.where((qb) => {
if (searchCriteria.searchTerm) {
qb.where('items.itemName', 'like', `%${searchCriteria.searchTerm}%`);
}
if (searchCriteria.itemType) {
qb.orWhere('items.itemType', '=', searchCriteria.itemType);
}
if (searchCriteria.category) {
qb.orWhere('items.category', '=', searchCriteria.category);
}
});