diff --git a/backend/src/routes/equipment.js b/backend/src/routes/equipment.js index 885cd0d..c935f1b 100644 --- a/backend/src/routes/equipment.js +++ b/backend/src/routes/equipment.js @@ -194,7 +194,10 @@ router.get('/spreaders', async (req, res, next) => { LEFT JOIN equipment_categories ec ON ue.category_id = ec.id WHERE ue.user_id = $1 AND ue.is_active = true - AND (ec.name ILIKE '%spreader%' OR ue.spreader_type IS NOT NULL) + AND (ec.name ILIKE '%spreader%' + OR ue.spreader_type IS NOT NULL + OR ue.custom_name ILIKE '%spreader%' + OR ue.manufacturer ILIKE '%spreader%') ORDER BY ue.custom_name, ue.manufacturer, ue.model`, [req.user.id] ); diff --git a/backend/src/utils/validation.js b/backend/src/utils/validation.js index c5f4d00..27e7c9f 100644 --- a/backend/src/utils/validation.js +++ b/backend/src/utils/validation.js @@ -108,7 +108,13 @@ const userProductSchema = Joi.object({ Joi.string().allow(''), Joi.allow(null) ).optional() - }).or('equipmentId', 'spreaderBrand') // Must have either equipment reference or brand + }).when('equipmentId', { + is: Joi.exist(), + then: Joi.object(), // When equipmentId exists, spreaderBrand is optional + otherwise: Joi.object({ + spreaderBrand: Joi.string().max(100).required() // When no equipmentId, require spreaderBrand + }) + }) ).optional() });