transtaction commits on several endpoints
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-12-16 10:56:10 +01:00
parent 2bfc6a5987
commit 5a448234d6
5 changed files with 106 additions and 70 deletions

View File

@ -33,6 +33,7 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
const isEditable = await Self.app.models.Order.isEditable(params.orderFk, myOptions);
if (!isEditable)
@ -50,6 +51,12 @@ module.exports = Self => {
}
await Promise.all(promises);
if (tx) await tx.commit();
return true;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -33,6 +33,7 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
if (!params.rows || !params.rows.length)
throw new UserError('There is nothing to delete');
@ -45,6 +46,14 @@ module.exports = Self => {
for (let i = 0; i < params.rows.length; i++)
promises.push(Self.app.models.OrderRow.destroyById(params.rows[i], myOptions));
return Promise.all(promises);
const deletions = await Promise.all(promises);
if (tx) await tx.commit();
return deletions;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -44,6 +44,7 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
const address = await Self.app.models.Address.findOne({
where: {id: addressId},
fields: ['clientFk'],
@ -71,6 +72,12 @@ module.exports = Self => {
'SALIX'
], myOptions);
if (tx) await tx.commit();
return result[0].vOrderId;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -30,6 +30,7 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
const ticket = await Self.app.models.Ticket.findOne({
where: {id: ticketFk}
}, myOptions);
@ -40,6 +41,12 @@ module.exports = Self => {
const orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk, myOptions);
if (tx) await tx.commit();
return orderID;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -43,7 +43,7 @@ module.exports = Self => {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const order = await models.Order.findById(id, null, myOptions);
const orderRows = await models.OrderRow.find({where: {orderFk: id}}, myOptions);
@ -60,6 +60,12 @@ module.exports = Self => {
if (Object.keys(updateParams).length)
await order.updateAttributes(updateParams, myOptions);
if (tx) await tx.commit();
return order;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};