72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
|
|
// src/modules/watchdog/model/email.model.js
|
|||
|
|
|
|||
|
|
function prepareNotificationPayload(tickets) {
|
|||
|
|
return {
|
|||
|
|
subject: buildSubject(tickets),
|
|||
|
|
bodyEmail: buildBodyEmail(tickets),
|
|||
|
|
recipients: getRecipients(),
|
|||
|
|
cc: getCc()
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function buildSubject(tickets) {
|
|||
|
|
|
|||
|
|
if (tickets.length === 0) {
|
|||
|
|
return '[GOLEIRO] Nenhum chamado foi agarrado';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return `🧤 [GOLEIRO] ${tickets.length} chamados foram agarrados`;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function buildBodyEmail(tickets) {
|
|||
|
|
let body = `
|
|||
|
|
<p>🚨 <strong>Atenção!</strong></p>
|
|||
|
|
<p>O goleiro defendeu os seguintes chamados:</p>
|
|||
|
|
<p>Esses chamados foram <strong>fechados no Hubsoft</strong>, mas ainda constam como <strong>abertos no GLPI</strong>.</p>
|
|||
|
|
<br>
|
|||
|
|
<ul>
|
|||
|
|
`;
|
|||
|
|
|
|||
|
|
tickets.forEach(ticket => {
|
|||
|
|
body += `
|
|||
|
|
<li>
|
|||
|
|
Hubsoft ID: <strong>${ticket.hubsoft_ticket_id}</strong><br>
|
|||
|
|
GLPI ID: <strong>${ticket.glpi_ticket_id ?? 'não encontrado'}</strong><br>
|
|||
|
|
Fechado em: ${formatDate(ticket.hubsoft_closed_at)}
|
|||
|
|
</li>
|
|||
|
|
<br>
|
|||
|
|
`;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
body += `
|
|||
|
|
</ul>
|
|||
|
|
<br>
|
|||
|
|
<p>⚽ Favor verificar e alinhar os status no GLPI.</p>
|
|||
|
|
<p><em>Watchdog Hub × GLPI</em></p>
|
|||
|
|
`;
|
|||
|
|
|
|||
|
|
return body;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function formatDate(date) {
|
|||
|
|
try {
|
|||
|
|
return new Date(date).toLocaleString('pt-BR');
|
|||
|
|
} catch {
|
|||
|
|
return date;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function getRecipients() {
|
|||
|
|
return process.env.WATCHDOG_RECIPIENT_EMAILS?.split(',') || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getCc() {
|
|||
|
|
return process.env.WATCHDOG_CC_EMAILS?.split(',') || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
module.exports = {
|
|||
|
|
prepareNotificationPayload
|
|||
|
|
};
|