fix some stuff
This commit is contained in:
@@ -181,7 +181,7 @@ router.post('/', validateRequest(spreaderSettingSchema), async (req, res, next)
|
||||
router.put('/:id', validateParams(idParamSchema), validateRequest(spreaderSettingSchema), async (req, res, next) => {
|
||||
try {
|
||||
const settingId = req.params.id;
|
||||
const { productId, userProductId, spreaderBrand, spreaderModel, settingValue, rateDescription, notes } = req.body;
|
||||
const { productId, userProductId, equipmentId, spreaderBrand, spreaderModel, settingValue, rateDescription, notes } = req.body;
|
||||
|
||||
// Check if setting exists and user has permission to edit it
|
||||
let checkQuery;
|
||||
@@ -206,13 +206,25 @@ router.put('/:id', validateParams(idParamSchema), validateRequest(spreaderSettin
|
||||
throw new AppError('Spreader setting not found', 404);
|
||||
}
|
||||
|
||||
// If equipment ID is provided, verify it belongs to the user
|
||||
if (equipmentId) {
|
||||
const equipmentCheck = await pool.query(
|
||||
'SELECT id FROM user_equipment WHERE id = $1 AND user_id = $2',
|
||||
[equipmentId, req.user.id]
|
||||
);
|
||||
|
||||
if (equipmentCheck.rows.length === 0) {
|
||||
throw new AppError('Equipment not found', 404);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await pool.query(
|
||||
`UPDATE product_spreader_settings
|
||||
SET spreader_brand = $1, spreader_model = $2, setting_value = $3,
|
||||
rate_description = $4, notes = $5
|
||||
WHERE id = $6
|
||||
SET equipment_id = $1, spreader_brand = $2, spreader_model = $3, setting_value = $4,
|
||||
rate_description = $5, notes = $6
|
||||
WHERE id = $7
|
||||
RETURNING *`,
|
||||
[spreaderBrand, spreaderModel, settingValue, rateDescription, notes, settingId]
|
||||
[equipmentId, spreaderBrand, spreaderModel, settingValue, rateDescription, notes, settingId]
|
||||
);
|
||||
|
||||
const setting = result.rows[0];
|
||||
@@ -223,6 +235,7 @@ router.put('/:id', validateParams(idParamSchema), validateRequest(spreaderSettin
|
||||
data: {
|
||||
setting: {
|
||||
id: setting.id,
|
||||
equipmentId: setting.equipment_id,
|
||||
spreaderBrand: setting.spreader_brand,
|
||||
spreaderModel: setting.spreader_model,
|
||||
settingValue: setting.setting_value,
|
||||
|
||||
Reference in New Issue
Block a user