2026-01-12 16:42:08 -03:00
|
|
|
|
// src/modules/watchdog/model/email.model.js
|
|
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
function prepareNotificationPayload(tickets, type = 'func') {
|
|
|
|
|
|
const normalizedType = String(type || 'func').toLowerCase()
|
|
|
|
|
|
const isAdm = normalizedType === 'adm'
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
subject: buildSubject(tickets, normalizedType),
|
|
|
|
|
|
bodyEmail: isAdm ? buildBodyEmailAdm(tickets) : buildBodyEmail(tickets),
|
|
|
|
|
|
recipients: getRecipients(normalizedType),
|
|
|
|
|
|
cc: getCc(normalizedType)
|
|
|
|
|
|
}
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
function buildSubject(tickets, type = 'func') {
|
|
|
|
|
|
if (type === 'adm') {
|
2026-01-12 16:42:08 -03:00
|
|
|
|
if (tickets.length === 0) {
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return '🧤⚽ [GOLEIRO ADM] Nenhum chamado foi para os pênaltis'
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
2026-01-20 17:36:28 -03:00
|
|
|
|
|
|
|
|
|
|
return `🚨⚽ [GOLEIRO ADM] ${tickets.length} chamados foram para os pênaltis`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tickets.length === 0) {
|
|
|
|
|
|
return '🧤 [GOLEIRO] Nenhum chamado foi agarrado'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return `🧤 [GOLEIRO] ${tickets.length} chamados foram agarrados`
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function buildBodyEmail(tickets) {
|
2026-01-14 17:51:49 -03:00
|
|
|
|
let body = `
|
2026-01-20 17:36:28 -03:00
|
|
|
|
<p>🧤 <strong>Atenção, time!</strong></p>
|
|
|
|
|
|
<p>O goleiro entrou em ação e defendeu os seguintes chamados:</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
Esses chamados foram <strong>fechados no Hubsoft</strong>,
|
|
|
|
|
|
mas ainda constam como <strong>abertos no GLPI</strong>.
|
|
|
|
|
|
</p>
|
2026-01-14 17:51:49 -03:00
|
|
|
|
<br>
|
|
|
|
|
|
<ul>
|
2026-01-20 17:36:28 -03:00
|
|
|
|
`
|
2026-01-12 16:42:08 -03:00
|
|
|
|
|
2026-01-14 17:51:49 -03:00
|
|
|
|
tickets.forEach(ticket => {
|
2026-01-12 16:42:08 -03:00
|
|
|
|
body += `
|
2026-01-14 17:51:49 -03:00
|
|
|
|
<li>
|
2026-01-20 17:36:28 -03:00
|
|
|
|
🧾 <strong>Protocolo Hubsoft:</strong> ${ticket.protocolo_hub}<br>
|
|
|
|
|
|
🧠 <strong>Mundiale ID:</strong> ${ticket.ticket_mundiale}<br>
|
|
|
|
|
|
🛠 <strong>GLPI ID:</strong> ${ticket.glpi_ticket_id ?? 'não encontrado'}<br>
|
|
|
|
|
|
⏱ <strong>Fechado em:</strong> ${formatDate(ticket.closed_at)}
|
2026-01-14 17:51:49 -03:00
|
|
|
|
</li>
|
|
|
|
|
|
<br>
|
2026-01-20 17:36:28 -03:00
|
|
|
|
`
|
|
|
|
|
|
})
|
2026-01-14 17:51:49 -03:00
|
|
|
|
|
|
|
|
|
|
body += `
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<br>
|
2026-01-20 17:36:28 -03:00
|
|
|
|
<p>⚠️ Favor verificar e alinhar os status no GLPI.</p>
|
2026-01-14 17:51:49 -03:00
|
|
|
|
<p><em>Watchdog Hub × GLPI</em></p>
|
2026-01-20 17:36:28 -03:00
|
|
|
|
`
|
2026-01-14 17:51:49 -03:00
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return body
|
2026-01-14 17:51:49 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
function buildBodyEmailAdm(tickets) {
|
|
|
|
|
|
let body = `
|
|
|
|
|
|
<p>🚨⚽ <strong>Pênalti!</strong></p>
|
|
|
|
|
|
<p>Os seguintes chamados passaram da defesa inicial:</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
Esses chamados foram <strong>fechados no Hubsoft há mais de 1 hora</strong>
|
|
|
|
|
|
e ainda <strong>não tiveram atualização no GLPI</strong>.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
`
|
2026-01-12 16:42:08 -03:00
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
tickets.forEach(ticket => {
|
|
|
|
|
|
body += `
|
|
|
|
|
|
<li>
|
|
|
|
|
|
🧾 <strong>Protocolo Hubsoft:</strong> ${ticket.protocolo_hub}<br>
|
|
|
|
|
|
🧠 <strong>Mundiale ID:</strong> ${ticket.ticket_mundiale}<br>
|
|
|
|
|
|
🛠 <strong>GLPI ID:</strong> ${ticket.glpi_ticket_id ?? 'não encontrado'}<br>
|
|
|
|
|
|
⏱ <strong>Fechado em:</strong> ${formatDate(ticket.closed_at)}
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<br>
|
|
|
|
|
|
`
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
body += `
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<br>
|
|
|
|
|
|
<p>📢 Favor acionar o time responsável e alinhar os status no GLPI.</p>
|
|
|
|
|
|
<p><em>Watchdog Hub × GLPI</em></p>
|
|
|
|
|
|
`
|
2026-01-14 17:51:49 -03:00
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return body
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
function formatDate(value) {
|
|
|
|
|
|
if (!value) return 'não informado'
|
2026-01-12 16:42:08 -03:00
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
const d = new Date(value)
|
|
|
|
|
|
if (Number.isNaN(d.getTime())) return String(value)
|
2026-01-14 17:51:49 -03:00
|
|
|
|
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return d.toLocaleString('pt-BR', { timeZone: 'America/Sao_Paulo' })
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getRecipients() {
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return process.env.WATCHDOG_RECIPIENT_EMAILS?.split(',') || []
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getCc() {
|
2026-01-20 17:36:28 -03:00
|
|
|
|
return process.env.WATCHDOG_CC_EMAILS?.split(',') || []
|
2026-01-12 16:42:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2026-01-20 17:36:28 -03:00
|
|
|
|
prepareNotificationPayload
|
|
|
|
|
|
}
|