64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
|
const smtp = require('vn-print/core/smtp');
|
||
|
const config = require('vn-print/core/config');
|
||
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('sendToSupport', {
|
||
|
description: 'Send mail to support',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [
|
||
|
{
|
||
|
arg: 'subject',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
description: 'The subject'
|
||
|
},
|
||
|
{
|
||
|
arg: 'reason',
|
||
|
type: 'string',
|
||
|
description: 'The reason'
|
||
|
},
|
||
|
{
|
||
|
arg: 'additionalData',
|
||
|
type: 'object',
|
||
|
required: true,
|
||
|
description: 'The additional data'
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/send-to-support`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.sendToSupport = async(ctx, subject, reason, additionalData) => {
|
||
|
const emailUser =
|
||
|
await Self.app.models.EmailUser.findById(ctx.req.accessToken.userId, {fields: ['email']});
|
||
|
|
||
|
let html = `<strong>Motivo</strong>:<br/>${reason}<br/>`;
|
||
|
for (const data in additionalData) {
|
||
|
tryJson(additionalData[data]);
|
||
|
html += `<strong>${data}</strong>:<br/>${tryJson(additionalData[data])}<br/>`;
|
||
|
}
|
||
|
console.log(subject, reason, additionalData);
|
||
|
console.log(html);
|
||
|
smtp.send({
|
||
|
to: config.app.reportEmail,
|
||
|
replyTo: emailUser.email,
|
||
|
subject: '[Support-Salix] ' + subject,
|
||
|
html
|
||
|
});
|
||
|
};
|
||
|
|
||
|
function tryJson(value) {
|
||
|
try {
|
||
|
return JSON.parse(value);
|
||
|
} catch (e) {
|
||
|
return value;
|
||
|
}
|
||
|
}
|
||
|
};
|