salix/modules/invoiceIn/back/methods/invoice-in/unbilledClientsCsv.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 => {
2023-03-16 08:35:00 +00:00
Self.remoteMethodCtx('unbilledClientsCsv', {
description: 'Returns the unbilled clients as .csv',
2023-03-10 11:49:20 +00:00
accessType: 'READ',
accepts: [{
2023-03-16 08:35:00 +00:00
arg: 'unbilledClients',
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: {
2023-03-16 08:35:00 +00:00
path: '/unbilledClientsCsv',
2023-03-10 11:49:20 +00:00
verb: 'GET'
}
});
2023-03-16 08:35:00 +00:00
Self.unbilledClientsCsv = async ctx => {
2023-03-10 11:49:20 +00:00
const args = ctx.args;
2023-03-16 08:35:00 +00:00
const content = toCSV(args.unbilledClients);
2023-03-10 11:49:20 +00:00
return [
content,
'text/csv',
2023-03-16 08:35:00 +00:00
`attachment; filename="unbilled-clients-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"`
2023-03-10 11:49:20 +00:00
];
};
};