From 7c7d21301ce7d4f0303e3b1c51b4e8d5198d0044 Mon Sep 17 00:00:00 2001 From: Stefano Rivoir Date: Tue, 9 Sep 2025 10:53:31 +0200 Subject: [PATCH] Add search parameter to item types list Fixes #391 --- api/v1/controllers/itemtypes.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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