fix(commit): refs #6403 hotFix add commit #2088
|
@ -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);
|
||||||
|
@ -86,7 +89,13 @@ module.exports = Self => {
|
||||||
const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml');
|
const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml');
|
||||||
const file = getTextByTag(getLabelResponse, 'EtiquetaFile');
|
const file = getTextByTag(getLabelResponse, 'EtiquetaFile');
|
||||||
|
|
||||||
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
try {
|
||||||
|
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (error) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue