refs #6915 master into test #2092
|
@ -25,12 +25,15 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.createShipment = async(expeditionFk, options) => {
|
Self.createShipment = async(expeditionFk, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction)
|
if (!myOptions.transaction) {
|
||||||
myOptions.transaction = await Self.beginTransaction({});
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const mrw = await models.MrwConfig.findOne(null, myOptions);
|
const mrw = await models.MrwConfig.findOne(null, myOptions);
|
||||||
|
@ -88,10 +91,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
||||||
await myOptions.transaction.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await myOptions.transaction.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw new UserError(`Cant update the expedition`);
|
throw new UserError(`Cant update `);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ const expedition1 = {
|
||||||
let tx;
|
let tx;
|
||||||
let options;
|
let options;
|
||||||
|
|
||||||
describe('MRWConfig createShipment()', () => {
|
fdescribe('MRWConfig createShipment()', () => {
|
||||||
beforeEach(async() => {
|
beforeEach(async() => {
|
||||||
options = tx = undefined;
|
options = tx = undefined;
|
||||||
tx = await models.MrwConfig.beginTransaction({});
|
tx = await models.MrwConfig.beginTransaction({});
|
||||||
|
|
Loading…
Reference in New Issue