diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 99daac512..d452b03fe 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -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); + } };