refactor: code repetead

This commit is contained in:
Vicent Llopis 2022-10-17 08:01:55 +02:00
parent a036578832
commit a11ef73dfb
1 changed files with 13 additions and 11 deletions

View File

@ -141,17 +141,9 @@ module.exports = Self => {
};
await models.SaleComponent.destroyAll(filter, myOptions);
newComponent = models.SaleComponent.create({
saleFk: sale.id,
value: value,
componentFk: componentId
}, myOptions);
} else {
newComponent = models.SaleComponent.create({
saleFk: sale.id,
value: value,
componentFk: componentId}, myOptions);
}
await createSaleComponent(sale.id, value, componentId, myOptions);
} else
await createSaleComponent(sale.id, value, componentId, myOptions);
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
@ -198,4 +190,14 @@ module.exports = Self => {
throw e;
}
};
async function createSaleComponent(saleId, value, componentId, myOptions) {
const models = Self.app.models;
newComponent = models.SaleComponent.create({
saleFk: saleId,
value: value,
componentFk: componentId
}, myOptions);
}
};