3092-module_transactions #740

Merged
joan merged 41 commits from 3092-module_transactions into dev 2021-10-18 07:42:24 +00:00
1 changed files with 66 additions and 59 deletions
Showing only changes of commit de7af0fee2 - Show all commits

View File

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