4616-ticket.sale_mana #1088

Merged
vicent merged 14 commits from 4616-ticket.sale_mana into dev 2022-11-02 13:48:21 +00:00
1 changed files with 37 additions and 4 deletions
Showing only changes of commit 86b7e9cabe - Show all commits

View File

@ -115,10 +115,43 @@ module.exports = Self => {
for (let sale of sales) {
const oldDiscount = sale.discount;
const value = ((-sale.price * newDiscount) / 100);
const newComponent = models.SaleComponent.upsert({
saleFk: sale.id,
value: value,
componentFk: componentId}, myOptions);
const manaComponent = await models.Component.findOne({
where: {code: 'mana'}
}, myOptions);
const manaClaimComponent = await models.Component.findOne({
where: {code: 'manaClaim'}
}, myOptions);
const oldComponent = await models.SaleComponent.find({
where: {
and: [
{saleFk: sale.id},
{componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}}
]
}
}, myOptions);
let newComponent;
vicent marked this conversation as resolved Outdated
Outdated
Review

No utilizar variables globales, es más dificil de hacer seguimiento

No utilizar variables globales, es más dificil de hacer seguimiento
if (oldComponent) {
const filter = {
saleFk: sale.id,
componentFk: oldComponent.componentFk
};
await models.SaleComponent.destroyAll(filter, myOptions);
vicent marked this conversation as resolved Outdated
Outdated
Review

Asignar el resultado de esta función (Promesa) a una variable, y hacer el push al array.

Asignar el resultado de esta función (Promesa) a una variable, y hacer el push al array.
newComponent = models.SaleComponent.create({
saleFk: sale.id,
value: value,
vicent marked this conversation as resolved Outdated
Outdated
Review

Esta linea está repetida en ambos casos, se puede extraer fuera del condicional

Esta linea está repetida en ambos casos, se puede extraer fuera del condicional
componentFk: componentId
}, myOptions);
} else {
newComponent = models.SaleComponent.create({
saleFk: sale.id,
value: value,
componentFk: componentId}, myOptions);
}
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);