refator: borrada variable global y añadida Promesa al array
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-10-26 08:23:36 +02:00
parent a8dfc9d06f
commit 925565d3d2
1 changed files with 5 additions and 5 deletions

View File

@ -133,20 +133,20 @@ module.exports = Self => {
}
}, myOptions);
let newComponent;
let deletedComponent;
if (oldComponent) {
const filter = {
saleFk: sale.id,
componentFk: oldComponent.componentFk
};
await models.SaleComponent.destroyAll(filter, myOptions);
deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions);
}
await createSaleComponent(sale.id, value, componentId, myOptions);
const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions);
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
promises.push(newComponent, updatedSale);
promises.push(newComponent, updatedSale, deletedComponent);
const change = `${oldDiscount}% ➔ *${newDiscount}%*`;
changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`;
@ -193,7 +193,7 @@ module.exports = Self => {
async function createSaleComponent(saleId, value, componentId, myOptions) {
const models = Self.app.models;
newComponent = models.SaleComponent.create({
return models.SaleComponent.create({
saleFk: saleId,
value: value,
componentFk: componentId