61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
const {Email} = require('vn-print');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('creditRequestHtml', {
|
|
description: 'Returns the credit request email preview',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The client 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/credit-request-html',
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.creditRequestHtml = async(ctx, id) => {
|
|
const {accessToken} = ctx.req;
|
|
const args = Object.assign({}, ctx.args);
|
|
const params = {lang: ctx.req.getLocale()};
|
|
|
|
delete args.ctx;
|
|
for (const param in args)
|
|
params[param] = args[param];
|
|
|
|
params.isPreview = true;
|
|
params.access_token = accessToken.id;
|
|
|
|
const report = new Email('credit-request', params);
|
|
const html = await report.render();
|
|
|
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
|
};
|
|
};
|