From 792f18671572aef3b085a48c0736f5ed35af3f26 Mon Sep 17 00:00:00 2001 From: Jake Kasper Date: Mon, 25 Aug 2025 09:18:52 -0400 Subject: [PATCH] moaisf --- backend/src/routes/equipment.js | 11 +++++++++-- backend/src/utils/validation.js | 17 ++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/backend/src/routes/equipment.js b/backend/src/routes/equipment.js index ec8e6a9..7993580 100644 --- a/backend/src/routes/equipment.js +++ b/backend/src/routes/equipment.js @@ -194,8 +194,15 @@ 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 - -- Temporarily show all equipment so user can identify spreaders - -- TODO: Add proper spreader identification/categorization + AND ( + ec.name ILIKE '%spreader%' + OR ue.spreader_type IS NOT NULL + OR ue.custom_name ILIKE '%spreader%' + OR ue.manufacturer ILIKE '%spreader%' + OR ue.manufacturer ILIKE '%lesco%' + ) + AND ue.custom_name NOT ILIKE '%nozzle%' + AND ue.custom_name NOT ILIKE '%sprayer%' 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 cfd811a..11c4082 100644 --- a/backend/src/utils/validation.js +++ b/backend/src/utils/validation.js @@ -108,14 +108,17 @@ const userProductSchema = Joi.object({ Joi.string().allow(''), Joi.allow(null) ).optional() - }).when('equipmentId', { - is: Joi.number().positive(), - then: Joi.object(), // When equipmentId is a positive number, spreaderBrand is optional - otherwise: Joi.object({ - spreaderBrand: Joi.string().max(100).required() // When no valid equipmentId, require spreaderBrand - }) - }) + }).custom((value, helpers) => { + // Custom validation: require either equipmentId OR spreaderBrand + if (value.equipmentId || value.spreaderBrand) { + return value; // Valid if either exists + } + return helpers.error('custom.equipmentOrBrand'); + }, 'Equipment or Brand validation') ).optional() + .messages({ + 'custom.equipmentOrBrand': 'Either equipmentId or spreaderBrand must be provided' + }) }); // Application validation schemas