salix/back/methods/osticket/sendToSupport.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

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: '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, reason, additionalData) => {
2024-11-13 16:35:27 +00:00
const userId = ctx.req.accessToken.userId;
const emailUser =
2024-11-13 16:35:27 +00:00
await Self.app.models.EmailUser.findById(userId, {fields: ['email']});
const {code, message, path, request, status, statusText, config: errConfig, name} = additionalData;
2024-11-13 16:35:27 +00:00
let html = `<h2>Motivo: ${reason}</h2>`;
html += `<h3>Usuario: ${userId} ${emailUser.email}</h3>`;
html += `<h3>Additional Data:</h3>`;
html += `<ul><li>Code: ${code}</li>`;
html += `<li>Message: ${message}</li>`;
html += `<li>Path: ${path}</li>`;
html += `<li>Request: ${request}</li>`;
html += `<li>Status: ${status}</li>`;
html += `<li>StatusText: ${statusText}</li>`;
html += `<li>Config:</li><ul style="list-style-type: square;">`;
for (const [key, val] of Object.entries(errConfig)) html += `<li>${key}: ${parse(val)}</li>`;
html += '</ul></ul>';
2024-04-04 11:32:39 +00:00
await smtp.send({
to: `${config.app.reportEmail}, ${emailUser.email}`,
2024-11-13 16:35:27 +00:00
subject: `[Support-Salix] ${path} ${name}: ${message}`,
html
});
};
2024-11-13 16:35:27 +00:00
function parse(value) {
try {
try {
value = JSON.parse(value);
} catch {}
return JSON.stringify(value, null, '&nbsp;').split('\n').join('<br>');
} catch {
return value;
}
}
};