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