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

54 lines
1.4 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'
}
});
2022-10-25 06:19:56 +00:00
Self.invoiceInEmail = async ctx => {
2022-10-24 13:15:23 +00:00
const args = Object.assign({}, ctx.args);
const params = {
2022-10-25 06:19:56 +00:00
recipient: args.recipient,
2022-10-24 13:15:23 +00:00
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();
};
};