asdf
This commit is contained in:
@@ -568,19 +568,40 @@ 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) {
|
||||||
await pool.query(
|
// Check if equipment exists and belongs to user if equipmentId is provided
|
||||||
`INSERT INTO product_spreader_settings
|
if (setting.equipmentId) {
|
||||||
(user_product_id, spreader_brand, spreader_model, setting_value, rate_description, notes)
|
const equipmentCheck = await pool.query(
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)`,
|
'SELECT id FROM user_equipment WHERE id = $1 AND user_id = $2',
|
||||||
[
|
[setting.equipmentId, req.user.id]
|
||||||
userProductId,
|
);
|
||||||
setting.spreaderBrand,
|
|
||||||
setting.spreaderModel,
|
if (equipmentCheck.rows.length === 0) {
|
||||||
setting.settingValue,
|
throw new AppError(`Equipment with id ${setting.equipmentId} not found`, 404);
|
||||||
setting.rateDescription,
|
}
|
||||||
setting.notes
|
|
||||||
]
|
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
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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