salix/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-10-24 13:15:23 +00:00
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, id) => {
const args = Object.assign({}, ctx.args);
const params = {
recipient: 'alexm@verdnatura.es', // args.recipient,
lang: ctx.req.getLocale()
};
console.log(id);
delete args.ctx;
for (const param in args)
params[param] = args[param];
console.log(params);
const email = new Email('invoiceIn', params);
return email.send();
};
};