This commit is contained in:
Jake Kasper
2025-08-25 09:18:52 -04:00
parent 6c70ebe0ae
commit 792f186715
2 changed files with 19 additions and 9 deletions

View File

@@ -194,8 +194,15 @@ router.get('/spreaders', async (req, res, next) => {
LEFT JOIN equipment_categories ec ON ue.category_id = ec.id LEFT JOIN equipment_categories ec ON ue.category_id = ec.id
WHERE ue.user_id = $1 WHERE ue.user_id = $1
AND ue.is_active = true AND ue.is_active = true
-- Temporarily show all equipment so user can identify spreaders AND (
-- TODO: Add proper spreader identification/categorization 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`, ORDER BY ue.custom_name, ue.manufacturer, ue.model`,
[req.user.id] [req.user.id]
); );

View File

@@ -108,14 +108,17 @@ const userProductSchema = Joi.object({
Joi.string().allow(''), Joi.string().allow(''),
Joi.allow(null) Joi.allow(null)
).optional() ).optional()
}).when('equipmentId', { }).custom((value, helpers) => {
is: Joi.number().positive(), // Custom validation: require either equipmentId OR spreaderBrand
then: Joi.object(), // When equipmentId is a positive number, spreaderBrand is optional if (value.equipmentId || value.spreaderBrand) {
otherwise: Joi.object({ return value; // Valid if either exists
spreaderBrand: Joi.string().max(100).required() // When no valid equipmentId, require spreaderBrand }
}) return helpers.error('custom.equipmentOrBrand');
}) }, 'Equipment or Brand validation')
).optional() ).optional()
.messages({
'custom.equipmentOrBrand': 'Either equipmentId or spreaderBrand must be provided'
})
}); });
// Application validation schemas // Application validation schemas