change compose to publish fix some other product stuff

This commit is contained in:
Jake Kasper
2025-08-24 14:11:47 -04:00
parent bd844d0a2e
commit 1758252d54
3 changed files with 195 additions and 11 deletions

View File

@@ -432,19 +432,15 @@ router.put('/user/:id', validateParams(idParamSchema), validateRequest(userProdu
customRateUnit,
notes,
isAdvancedEdit,
// Advanced edit fields (will be ignored for now as schema doesn't support them)
// Advanced edit fields
brand,
categoryId,
productType,
activeIngredients,
description
description,
spreaderSettings
} = req.body;
// Log warning if advanced edit is attempted (not fully supported yet)
if (isAdvancedEdit) {
console.warn(`Advanced edit attempted for user product ${userProductId}. Only basic fields will be updated.`);
}
// Check if user product exists and belongs to user
const checkResult = await pool.query(
'SELECT id FROM user_products WHERE id = $1 AND user_id = $2',
@@ -491,6 +487,32 @@ router.put('/user/:id', validateParams(idParamSchema), validateRequest(userProdu
const userProduct = result.rows[0];
// Handle spreader settings for granular products
if (spreaderSettings && Array.isArray(spreaderSettings) && productType === 'granular') {
// First, delete existing spreader settings for this user product
await pool.query(
'DELETE FROM product_spreader_settings WHERE user_product_id = $1',
[userProductId]
);
// 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
]
);
}
}
res.json({
success: true,
message: 'Custom product updated successfully',