54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
const {Email} = require('vn-print');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('invoiceInEmail', {
|
|
description: 'Sends the invoice in email with an attached PDF',
|
|
accessType: 'WRITE',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The invoice id',
|
|
http: {source: 'path'}
|
|
},
|
|
{
|
|
arg: 'recipient',
|
|
type: 'string',
|
|
description: 'The recipient email',
|
|
required: true,
|
|
},
|
|
{
|
|
arg: 'recipientId',
|
|
type: 'number',
|
|
description: 'The recipient id to send to the recipient preferred language',
|
|
required: false
|
|
}
|
|
],
|
|
returns: {
|
|
type: ['object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: '/:id/invoice-in-email',
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.invoiceInEmail = async ctx => {
|
|
const args = Object.assign({}, ctx.args);
|
|
const params = {
|
|
recipient: args.recipient,
|
|
lang: ctx.req.getLocale()
|
|
};
|
|
|
|
delete args.ctx;
|
|
for (const param in args)
|
|
params[param] = args[param];
|
|
|
|
const email = new Email('invoiceIn', params);
|
|
|
|
return email.send();
|
|
};
|
|
};
|