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
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]
);

View File

@@ -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