2023-06-30 12:24:50 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-07-14 12:30:08 +00:00
|
|
|
Self.sendToSupport = async(ctx, reason, additionalData) => {
|
2024-11-13 16:35:27 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2023-06-30 12:24:50 +00:00
|
|
|
const emailUser =
|
2024-11-13 16:35:27 +00:00
|
|
|
await Self.app.models.EmailUser.findById(userId, {fields: ['email']});
|
2023-06-30 12:24:50 +00:00
|
|
|
|
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>`;
|
2024-11-14 09:47:39 +00:00
|
|
|
html += '<ul>';
|
|
|
|
for (const [key, val] of Object.entries(additionalData)) {
|
|
|
|
if (key !== 'config') html += `<li>${key}: ${parse(val)}</li>`;
|
|
|
|
else {
|
|
|
|
html += `<li>${key}:</li><ul style="list-style-type: square;">`;
|
|
|
|
for (const [confKey, confVal] of Object.entries(val))
|
|
|
|
html += `<li>${confKey}: ${parse(confVal)}</li>`;
|
|
|
|
html += '</ul>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
html += '</ul>';
|
2023-07-14 12:30:08 +00:00
|
|
|
|
2024-11-14 09:47:39 +00:00
|
|
|
const {message, path, name} = additionalData;
|
2024-04-04 11:32:39 +00:00
|
|
|
await smtp.send({
|
2023-08-21 12:48:05 +00:00
|
|
|
to: `${config.app.reportEmail}, ${emailUser.email}`,
|
2024-11-13 16:35:27 +00:00
|
|
|
subject: `[Support-Salix] ${path} ${name}: ${message}`,
|
2023-06-30 12:24:50 +00:00
|
|
|
html
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-11-13 16:35:27 +00:00
|
|
|
function parse(value) {
|
2023-06-30 12:24:50 +00:00
|
|
|
try {
|
2023-07-14 12:30:08 +00:00
|
|
|
try {
|
|
|
|
value = JSON.parse(value);
|
|
|
|
} catch {}
|
|
|
|
return JSON.stringify(value, null, ' ').split('\n').join('<br>');
|
|
|
|
} catch {
|
2023-06-30 12:24:50 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|