56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
|
const {Report} = require('vn-print');
|
||
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('receiptPdf', {
|
||
|
description: 'Returns the receipt pdf',
|
||
|
accepts: [
|
||
|
{
|
||
|
arg: 'id',
|
||
|
type: 'number',
|
||
|
required: true,
|
||
|
description: 'The claim id',
|
||
|
http: {source: 'path'}
|
||
|
},
|
||
|
{
|
||
|
arg: 'recipientId',
|
||
|
type: 'number',
|
||
|
description: 'The recipient id',
|
||
|
required: false
|
||
|
}
|
||
|
],
|
||
|
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: '/:id/receipt-pdf',
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.receiptPdf = async(ctx, id) => {
|
||
|
const args = Object.assign({}, ctx.args);
|
||
|
const params = {lang: ctx.req.getLocale()};
|
||
|
|
||
|
delete args.ctx;
|
||
|
for (const param in args)
|
||
|
params[param] = args[param];
|
||
|
|
||
|
const report = new Report('receipt', params);
|
||
|
const stream = await report.toPdfStream();
|
||
|
|
||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||
|
};
|
||
|
};
|