This commit is contained in:
Jake Kasper
2025-08-25 09:52:58 -04:00
parent a374fff7e6
commit d9ab650d39
2 changed files with 41 additions and 13 deletions

View File

@@ -568,19 +568,40 @@ router.put('/user/:id', validateParams(idParamSchema), validateRequest(userProdu
// Then add the new settings
for (const setting of spreaderSettings) {
await pool.query(
`INSERT INTO product_spreader_settings
(user_product_id, spreader_brand, spreader_model, setting_value, rate_description, notes)
VALUES ($1, $2, $3, $4, $5, $6)`,
[
userProductId,
setting.spreaderBrand,
setting.spreaderModel,
setting.settingValue,
setting.rateDescription,
setting.notes
]
);
// Check if equipment exists and belongs to user if equipmentId is provided
if (setting.equipmentId) {
const equipmentCheck = await pool.query(
'SELECT id FROM user_equipment WHERE id = $1 AND user_id = $2',
[setting.equipmentId, req.user.id]
);
if (equipmentCheck.rows.length === 0) {
throw new AppError(`Equipment with id ${setting.equipmentId} not found`, 404);
}
await pool.query(
`INSERT INTO product_spreader_settings
(user_product_id, equipment_id, setting_value, rate_description, notes)
VALUES ($1, $2, $3, $4, $5)`,
[userProductId, setting.equipmentId, setting.settingValue,
setting.rateDescription, setting.notes]
);
} else {
// Fall back to legacy brand/model approach
await pool.query(
`INSERT INTO product_spreader_settings
(user_product_id, spreader_brand, spreader_model, setting_value, rate_description, notes)
VALUES ($1, $2, $3, $4, $5, $6)`,
[
userProductId,
setting.spreaderBrand,
setting.spreaderModel,
setting.settingValue,
setting.rateDescription,
setting.notes
]
);
}
}
}

View File

@@ -0,0 +1,7 @@
-- Make spreader_brand nullable to support equipment-based spreader settings
-- When equipment_id is used, spreader_brand can be null
ALTER TABLE product_spreader_settings
ALTER COLUMN spreader_brand DROP NOT NULL;
SELECT 'Made spreader_brand nullable for equipment-based settings!' as migration_status;