fixyfix
This commit is contained in:
@@ -17,7 +17,14 @@ const spreaderSettingSchema = Joi.object({
|
|||||||
settingValue: Joi.string().max(20).required(),
|
settingValue: Joi.string().max(20).required(),
|
||||||
rateDescription: Joi.string().max(200).allow(null, '').optional(),
|
rateDescription: Joi.string().max(200).allow(null, '').optional(),
|
||||||
notes: Joi.string().allow(null, '').optional()
|
notes: Joi.string().allow(null, '').optional()
|
||||||
}).xor('productId', 'userProductId').and('equipmentId', 'settingValue'); // Must have either productId or userProductId, but not both
|
}).xor('productId', 'userProductId')
|
||||||
|
.when('equipmentId', {
|
||||||
|
is: Joi.exist(),
|
||||||
|
then: Joi.object(), // When equipmentId exists, spreaderBrand is optional
|
||||||
|
otherwise: Joi.object({
|
||||||
|
spreaderBrand: Joi.string().max(100).required() // When no equipmentId, require spreaderBrand
|
||||||
|
})
|
||||||
|
}); // Must have either productId or userProductId, but not both
|
||||||
|
|
||||||
const idParamSchema = Joi.object({
|
const idParamSchema = Joi.object({
|
||||||
id: Joi.number().integer().positive().required()
|
id: Joi.number().integer().positive().required()
|
||||||
|
|||||||
@@ -73,18 +73,25 @@ const Products = () => {
|
|||||||
|
|
||||||
// Save spreader settings if any
|
// Save spreader settings if any
|
||||||
if (productData.spreaderSettings && productData.spreaderSettings.length > 0) {
|
if (productData.spreaderSettings && productData.spreaderSettings.length > 0) {
|
||||||
const settingPromises = productData.spreaderSettings.map(setting =>
|
const settingPromises = productData.spreaderSettings.map(setting => {
|
||||||
productSpreaderSettingsAPI.create({
|
const payload = {
|
||||||
userProductId: createdProduct.id,
|
userProductId: createdProduct.id,
|
||||||
equipmentId: setting.equipmentId ? parseInt(setting.equipmentId) : null,
|
|
||||||
// Legacy fields for backward compatibility
|
|
||||||
spreaderBrand: setting.spreaderBrand || null,
|
|
||||||
spreaderModel: setting.spreaderModel || null,
|
|
||||||
settingValue: setting.settingValue,
|
settingValue: setting.settingValue,
|
||||||
rateDescription: setting.rateDescription || null,
|
rateDescription: setting.rateDescription || null,
|
||||||
notes: setting.notes && setting.notes.trim() ? setting.notes.trim() : null
|
notes: setting.notes && setting.notes.trim() ? setting.notes.trim() : null
|
||||||
})
|
};
|
||||||
);
|
|
||||||
|
// Use equipment-based approach if equipmentId is available
|
||||||
|
if (setting.equipmentId) {
|
||||||
|
payload.equipmentId = parseInt(setting.equipmentId);
|
||||||
|
} else {
|
||||||
|
// Fall back to legacy approach
|
||||||
|
payload.spreaderBrand = setting.spreaderBrand;
|
||||||
|
payload.spreaderModel = setting.spreaderModel || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return productSpreaderSettingsAPI.create(payload);
|
||||||
|
});
|
||||||
|
|
||||||
await Promise.all(settingPromises);
|
await Promise.all(settingPromises);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user