const {toCSV} = require('vn-loopback/util/csv'); module.exports = Self => { Self.remoteMethodCtx('negativeBasesCsv', { description: 'Returns the negative bases as .csv', accessType: 'READ', accepts: [{ arg: 'negativeBases', type: ['object'], required: true }, { arg: 'from', type: 'date', description: 'From date' }, { arg: 'to', type: 'date', description: 'To date' }], returns: [ { arg: 'body', type: 'file', root: true }, { arg: 'Content-Type', type: 'String', http: {target: 'header'} }, { arg: 'Content-Disposition', type: 'String', http: {target: 'header'} } ], http: { path: '/negativeBasesCsv', verb: 'GET' } }); Self.negativeBasesCsv = async ctx => { const args = ctx.args; const content = toCSV(args.negativeBases); return [ content, 'text/csv', `attachment; filename="negative-bases-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"` ]; }; };