FIX: Renomear função handleMundialeTicket para handleTicket e atualizar lógica de verificação de escopo, permitindo que chamados fora do tipo mundiale sejam fechados

This commit is contained in:
Rafael Alves Lopes 2025-12-16 10:50:04 -03:00
parent dcdde87544
commit 809acae4b6

View File

@ -15,10 +15,10 @@ const e = require('express');
* @returns {Promise<object|null>} Um objeto com os IDs { hubsoftId, glpiId, syncId } ou null se não for aplicável. * @returns {Promise<object|null>} Um objeto com os IDs { hubsoftId, glpiId, syncId } ou null se não for aplicável.
*/ */
const handleMundialeTicket = async (glpiTicketId, ticketTitle) => { const handleTicket = async (glpiTicketId, ticketTitle) => {
try { try {
if (!ticketTitle.includes("Mundiale")) { if (!tolow(ticketTitle).includes("mundiale") || !tolow(ticketTitle).includes("implantacao") || !tolow(ticketTitle).includes("sac") || !tolow(ticketTitle).includes('cancelamento') || !tolow(ticketTitle).includes('troca de titularidade')) {
logInfo(`Ticket ID ${glpiTicketId} não é da Mundiale. Ignorando fechamento.`); logInfo(`Ticket ID ${glpiTicketId} esta fora do escopo do fluxo. Ignorando fechamento.`);
return null; return null;
} }
@ -45,7 +45,7 @@ const handleMundialeTicket = async (glpiTicketId, ticketTitle) => {
return null; return null;
} }
} catch (error) { } catch (error) {
logError(`Erro em handleMundialeTicket para o ticket ID ${glpiTicketId}:`, error); logError(`Erro em handleTicket para o ticket ID ${glpiTicketId}:`, error);
throw error; // Propaga o erro para o chamador throw error; // Propaga o erro para o chamador
} }
}; };
@ -102,7 +102,7 @@ const fechaTicket = async (bodyRequest) => {
const closingMessage = sanitizeGLPIComment({ content: rawClosingMessage }); const closingMessage = sanitizeGLPIComment({ content: rawClosingMessage });
try { try {
const ticketInfo = await handleMundialeTicket(glpiTicketId, ticketTitle); const ticketInfo = await handleTicket(glpiTicketId, ticketTitle);
if (ticketInfo) { if (ticketInfo) {
const closeResponse = await closeHubsoftTicket(ticketInfo.hubsoftId, closingMessage); const closeResponse = await closeHubsoftTicket(ticketInfo.hubsoftId, closingMessage);
@ -138,7 +138,7 @@ module.exports = { fechaTicket };
* *
* Funções: * Funções:
* - `fechaTicket(bodyRequest)`: Orquestra todo o processo de fechamento. * - `fechaTicket(bodyRequest)`: Orquestra todo o processo de fechamento.
* - `handleMundialeTicket(...)`: Verifica se o ticket é elegível para o fluxo e tenta obter uma trava no banco de dados para evitar processamento duplicado. * - `handleTicket(...)`: Verifica se o ticket é elegível para o fluxo e tenta obter uma trava no banco de dados para evitar processamento duplicado.
* - `closeHubsoftTicket(...)`: Interage com o `hubsoftService` para fechar o atendimento no HubSoft. Trata o caso onde o ticket está fechado. * - `closeHubsoftTicket(...)`: Interage com o `hubsoftService` para fechar o atendimento no HubSoft. Trata o caso onde o ticket está fechado.
* - `updateLocalDatabaseOnClose(...)`: Atualiza o status do ticket no banco de dados local após o fechamento bem-sucedido. * - `updateLocalDatabaseOnClose(...)`: Atualiza o status do ticket no banco de dados local após o fechamento bem-sucedido.
*/ */