diff --git a/api/v1/controllers/itemtypes.mjs b/api/v1/controllers/itemtypes.mjs index 1e31240..2f15d3e 100644 --- a/api/v1/controllers/itemtypes.mjs +++ b/api/v1/controllers/itemtypes.mjs @@ -65,11 +65,9 @@ export async function list (req, res, next) { const cache = await Cache.get('all', Cache.itemTypesKey) let itemtypes + // Build cache if necessary if (!cache) { itemtypes = await DB.itemtypes.findMany({ - where: { - description: { contains: search, mode: 'insensitive' } - }, orderBy: { description: 'asc' } @@ -79,6 +77,13 @@ export async function list (req, res, next) { itemtypes = cache } + // If search, filter the results + if (search) { + itemtypes = itemtypes.filter(itm => { + return itm.description.toLowerCase().includes(search.toLowerCase()) + }) + } + if (itemtypes.length === 0) { res.status(R.NOT_FOUND).send(R.ko('No item found')) return