refactor: code repetead
This commit is contained in:
parent
a036578832
commit
a11ef73dfb
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue