asdf
This commit is contained in:
@@ -568,6 +568,26 @@ router.put('/user/:id', validateParams(idParamSchema), validateRequest(userProdu
|
|||||||
|
|
||||||
// Then add the new settings
|
// Then add the new settings
|
||||||
for (const setting of spreaderSettings) {
|
for (const setting of spreaderSettings) {
|
||||||
|
// 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(
|
await pool.query(
|
||||||
`INSERT INTO product_spreader_settings
|
`INSERT INTO product_spreader_settings
|
||||||
(user_product_id, spreader_brand, spreader_model, setting_value, rate_description, notes)
|
(user_product_id, spreader_brand, spreader_model, setting_value, rate_description, notes)
|
||||||
@@ -583,6 +603,7 @@ router.put('/user/:id', validateParams(idParamSchema), validateRequest(userProdu
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
7
database/migrations/make_spreader_brand_nullable.sql
Normal file
7
database/migrations/make_spreader_brand_nullable.sql
Normal 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;
|
||||||
Reference in New Issue
Block a user