salix/modules/invoiceIn/back/methods/invoice-in/negativeBasesCsv.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-03-10 11:49:20 +00:00
const {toCSV} = require('vn-loopback/util/csv');
module.exports = Self => {
Self.remoteMethodCtx('negativeBasesCsv', {
description: 'Returns the negative bases as .csv',
2023-03-10 11:49:20 +00:00
accessType: 'READ',
accepts: [{
arg: 'negativeBases',
2023-03-10 11:49:20 +00:00
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',
2023-03-10 11:49:20 +00:00
verb: 'GET'
}
});
Self.negativeBasesCsv = async ctx => {
2023-03-10 11:49:20 +00:00
const args = ctx.args;
const content = toCSV(args.negativeBases);
2023-03-10 11:49:20 +00:00
return [
content,
'text/csv',
`attachment; filename="negative-bases-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"`
2023-03-10 11:49:20 +00:00
];
};
};