Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
20b68b4b41
|
@ -24,12 +24,13 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.cancelShipment = async expeditionFk => {
|
Self.cancelShipment = async expeditionFk => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const mrw = await models.MrwConfig.findOne();
|
const mrw = await models.MrwConfig.findOne();
|
||||||
const {externalId} = await models.Expedition.findById(expeditionFk);
|
const {externalId} = await models.Expedition.findById(expeditionFk);
|
||||||
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||||
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
||||||
const renderedXml = ejs.render(template, {mrw, externalId, clientType});
|
const renderedXml = ejs.render(template, {mrw, externalId, clientType});
|
||||||
|
|
||||||
|
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', renderedXml]);
|
||||||
const response = await axios.post(mrw.url, renderedXml, {
|
const response = await axios.post(mrw.url, renderedXml, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||||
|
@ -37,12 +38,11 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const xmlString = response.data;
|
const xmlString = response.data;
|
||||||
|
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipmentResponse', xmlString]);
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||||
|
|
||||||
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', xmlDoc]);
|
|
||||||
|
|
||||||
const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent;
|
const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent;
|
||||||
return result.toLowerCase().includes('se ha cancelado correctamente');
|
return ['no se ha encontrado', 'se ha cancelado correctamente'].some(res => result.toLowerCase().includes(res));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,7 +52,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
|
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
|
||||||
deletedExpeditions.push(deletedExpedition);
|
deletedExpeditions.push(deletedExpedition);
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
|
console.error('error: ', error);
|
||||||
notDeletedExpeditions.push(expeditionId);
|
notDeletedExpeditions.push(expeditionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue