const fs = require('fs'); const ejs = require('ejs'); module.exports = Self => { Self.remoteMethod('deleteShipmentRenderer', { description: 'Renders the data from an XML', accessType: 'READ', accepts: [{ arg: 'expeditionFk', type: 'number', required: true }], returns: { type: ['object'], root: true }, http: { path: `/deleteShipmentRenderer`, verb: 'GET' } }); Self.deleteShipmentRenderer = async expeditionFk => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ fields: ['client', 'user', 'password'] }); const expedition = await models.Expedition.findOne({ fields: ['id', 'externalId'], where: {id: expeditionFk} }); const data = { viaexpressConfig, externalId: expedition.externalId }; const template = fs.readFileSync(__dirname + '/deleteShipment.ejs', 'utf-8'); const renderedXml = ejs.render(template, data); return renderedXml; }; };