fix(transaction): priceDifference now commits its created transaction
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-10-15 15:59:59 +02:00 committed by joan
parent 8fabd378e7
commit ace1c9c84b
1 changed files with 66 additions and 59 deletions

View File

@ -66,6 +66,7 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
const isEditable = await Self.isEditable(ctx, args.id, myOptions);
if (!isEditable)
@ -109,10 +110,6 @@ module.exports = Self => {
for (difComponent of difComponents)
map.set(difComponent.saleFk, difComponent);
function round(value) {
return Math.round(value * 100) / 100;
}
for (sale of salesObj.items) {
const difComponent = map.get(sale.id);
@ -130,6 +127,16 @@ module.exports = Self => {
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
}
if (tx) await tx.commit();
return salesObj;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
function round(value) {
return Math.round(value * 100) / 100;
}
};