2023-06-13 13:05:37 +00:00
|
|
|
const axios = require('axios');
|
2023-06-20 12:07:36 +00:00
|
|
|
const {DOMParser} = require('xmldom');
|
2023-06-13 13:05:37 +00:00
|
|
|
|
|
|
|
module.exports = Self => {
|
2023-06-16 11:49:21 +00:00
|
|
|
Self.remoteMethod('internationalExpedition', {
|
2023-06-20 05:19:32 +00:00
|
|
|
description: 'Create an expedition and return a label',
|
2023-06-13 13:05:37 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'expeditionFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2023-06-16 11:49:21 +00:00
|
|
|
path: `/internationalExpedition`,
|
2023-06-13 13:05:37 +00:00
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-16 12:05:16 +00:00
|
|
|
Self.internationalExpedition = async (expeditionFk) => {
|
2023-06-16 12:24:47 +00:00
|
|
|
const models = Self.app.models;
|
2023-06-19 09:55:07 +00:00
|
|
|
|
|
|
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
2023-06-19 12:27:24 +00:00
|
|
|
fields: ['url']
|
|
|
|
});
|
2023-06-19 09:55:07 +00:00
|
|
|
|
2023-06-19 12:27:24 +00:00
|
|
|
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
|
|
|
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
|
|
|
}
|
|
|
|
});
|
2023-06-20 12:07:36 +00:00
|
|
|
|
|
|
|
const xmlString = response.data;
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
|
|
const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0];
|
|
|
|
const referenciaVx = referenciaVxElement.textContent;
|
2023-06-16 12:24:47 +00:00
|
|
|
|
2023-06-19 12:27:24 +00:00
|
|
|
return referenciaVx;
|
2023-06-13 13:05:37 +00:00
|
|
|
};
|
|
|
|
};
|