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) => {
|
2023-06-30 12:24:50 +00:00
|
|
|
const emailUser =
|
|
|
|
await Self.app.models.EmailUser.findById(ctx.req.accessToken.userId, {fields: ['email']});
|
|
|
|
|
|
|
|
let html = `<strong>Motivo</strong>:<br/>${reason}<br/>`;
|
2023-08-21 11:48:51 +00:00
|
|
|
html += `<strong>Usuario</strong>:<br/>${ctx.req.accessToken.userId} ${emailUser.email}<br/>`;
|
2023-07-14 12:30:08 +00:00
|
|
|
|
2023-11-27 11:58:07 +00:00
|
|
|
delete additionalData.backError.config.headers.Authorization;
|
|
|
|
const httpRequest = JSON.parse(additionalData?.httpRequest);
|
|
|
|
|
|
|
|
if (httpRequest)
|
|
|
|
delete httpRequest.config.headers.Authorization;
|
|
|
|
additionalData.httpRequest = httpRequest;
|
|
|
|
|
2023-07-14 12:30:08 +00:00
|
|
|
for (const data in additionalData)
|
|
|
|
html += `<strong>${data}</strong>:<br/>${tryParse(additionalData[data])}<br/>`;
|
|
|
|
|
2023-11-27 11:58:07 +00:00
|
|
|
const subjectReason = httpRequest?.data?.error;
|
2023-06-30 12:24:50 +00:00
|
|
|
smtp.send({
|
2023-08-21 12:48:05 +00:00
|
|
|
to: `${config.app.reportEmail}, ${emailUser.email}`,
|
2023-07-14 12:30:08 +00:00
|
|
|
subject:
|
|
|
|
'[Support-Salix] ' +
|
|
|
|
additionalData?.frontPath + ' ' +
|
|
|
|
subjectReason?.name + ':' +
|
|
|
|
subjectReason?.message,
|
2023-06-30 12:24:50 +00:00
|
|
|
html
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-07-14 12:30:08 +00:00
|
|
|
function tryParse(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|