// src/modules/watchdog/model/email.model.js 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) } } function buildSubject(tickets, type = 'func') { if (type === 'adm') { if (tickets.length === 0) { return '🧤⚽ [GOLEIRO ADM] Nenhum chamado foi para os pênaltis' } 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` } function buildBodyEmail(tickets) { let body = `
🧤 Atenção, time!
O goleiro entrou em ação e defendeu os seguintes chamados:
Esses chamados foram fechados no Hubsoft, mas ainda constam como abertos no GLPI.
⚠️ Favor verificar e alinhar os status no GLPI.
Watchdog Hub × GLPI
` return body } function buildBodyEmailAdm(tickets) { let body = `🚨⚽ Pênalti!
Os seguintes chamados passaram da defesa inicial:
Esses chamados foram fechados no Hubsoft há mais de 1 hora e ainda não tiveram atualização no GLPI.
📢 Favor acionar o time responsável e alinhar os status no GLPI.
Watchdog Hub × GLPI
` return body } function formatDate(value) { if (!value) return 'não informado' const d = new Date(value) if (Number.isNaN(d.getTime())) return String(value) return d.toLocaleString('pt-BR', { timeZone: 'America/Sao_Paulo' }) } function getRecipients(type) { if (type === 'adm') { return process.env.WATCHDOG_ADM_RECIPIENT_EMAILS?.split(',') || [] } return process.env.WATCHDOG_RECIPIENT_EMAILS?.split(',') || [] } function getCc(type) { if (type === 'adm') { return process.env.WATCHDOG_ADM_CC_EMAILS?.split(',') || [] } return process.env.WATCHDOG_CC_EMAILS?.split(',') || [] } module.exports = { prepareNotificationPayload }