feat(fix): refs #6403 add transaction to createShipment
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
parent
277bcafd89
commit
94b49efb1f
|
@ -25,12 +25,15 @@ module.exports = Self => {
|
|||
|
||||
Self.createShipment = async(expeditionFk, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction)
|
||||
myOptions.transaction = await Self.beginTransaction({});
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const models = Self.app.models;
|
||||
const mrw = await models.MrwConfig.findOne(null, myOptions);
|
||||
|
@ -88,10 +91,10 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
||||
await myOptions.transaction.commit();
|
||||
if (tx) await tx.commit();
|
||||
} catch (error) {
|
||||
await myOptions.transaction.rollback();
|
||||
throw new UserError(`Cant update the expedition`);
|
||||
if (tx) await tx.rollback();
|
||||
throw new UserError(`Cant update `);
|
||||
}
|
||||
return file;
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ const expedition1 = {
|
|||
let tx;
|
||||
let options;
|
||||
|
||||
describe('MRWConfig createShipment()', () => {
|
||||
fdescribe('MRWConfig createShipment()', () => {
|
||||
beforeEach(async() => {
|
||||
options = tx = undefined;
|
||||
tx = await models.MrwConfig.beginTransaction({});
|
||||
|
|
Loading…
Reference in New Issue