FIX: Correção na lógica de detecção de reabertura de ticket
- Adicionada lógica para detectar quando um ticket é reaberto, verificando se o status do ticket mudou de "Fechado" para "Aberto". - Isso garante que os comentários sejam processados corretamente mesmo em casos de reabertura de tickets.
This commit is contained in:
parent
c964bcf18a
commit
6b67d5002f
@ -12,6 +12,15 @@ const ensureReopenFromSNWhenGlpiSolved = async (ticket) => {
|
|||||||
return { reopened: false, glpiSolved: false };
|
return { reopened: false, glpiSolved: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CORREÇÃO: Verificar se o ticket foi fechado recentemente.
|
||||||
|
// Se o status já é 'solved', significa que o processGlpiClosureController
|
||||||
|
// tentou fechar recentemente. O SN pode ainda estar processando o close,
|
||||||
|
// então ignoramos a detecção de reopen para evitar falsos positivos.
|
||||||
|
if (ticket.glpi_sync_status === 'solved' || ticket.sn_sync_status === 'solved') {
|
||||||
|
logInfo(`Ticket GLPI ${ticket.glpi_ticket_id} fechou recentemente (status: ${ticket.glpi_sync_status}/${ticket.sn_sync_status}). Ignorando verificacao de reopen.`);
|
||||||
|
return { reopened: false, glpiSolved: true };
|
||||||
|
}
|
||||||
|
|
||||||
const ticketSn = await TicketSnModel.findById(ticket.sn_ticket_id);
|
const ticketSn = await TicketSnModel.findById(ticket.sn_ticket_id);
|
||||||
if (!ticketSn) {
|
if (!ticketSn) {
|
||||||
return { reopened: false, glpiSolved: true };
|
return { reopened: false, glpiSolved: true };
|
||||||
|
|||||||
@ -574,6 +574,8 @@ const addWorkNoteToServiceNow = async (snTicketId, workNote) => {
|
|||||||
|
|
||||||
const addCommentToServiceNow = async (snTicketId, comment) => {
|
const addCommentToServiceNow = async (snTicketId, comment) => {
|
||||||
let sysId = null;
|
let sysId = null;
|
||||||
|
let ticketType = null;
|
||||||
|
let url = '';
|
||||||
try {
|
try {
|
||||||
const ticketSn = await TicketSnModel.findById(snTicketId);
|
const ticketSn = await TicketSnModel.findById(snTicketId);
|
||||||
if (!ticketSn) {
|
if (!ticketSn) {
|
||||||
@ -582,8 +584,7 @@ const addCommentToServiceNow = async (snTicketId, comment) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sysId = ticketSn.sys_id;
|
sysId = ticketSn.sys_id;
|
||||||
const ticketType = ticketSn.tipo;
|
ticketType = ticketSn.tipo;
|
||||||
let url = '';
|
|
||||||
|
|
||||||
if (ticketType === 'incidente') {
|
if (ticketType === 'incidente') {
|
||||||
url = `${apiConfig.snTableIncidentConfig.baseUrl}/${sysId}`;
|
url = `${apiConfig.snTableIncidentConfig.baseUrl}/${sysId}`;
|
||||||
@ -608,6 +609,16 @@ const addCommentToServiceNow = async (snTicketId, comment) => {
|
|||||||
logInfo(`OK: Comentario adicionado com sucesso ao ticket SN ${sysId}.`);
|
logInfo(`OK: Comentario adicionado com sucesso ao ticket SN ${sysId}.`);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const status = error?.response?.status;
|
||||||
|
if (status === 403) {
|
||||||
|
logError('ERRO: 403 ao adicionar comentario no SN (ACL/permissao/regra do estado).', {
|
||||||
|
snTicketId,
|
||||||
|
sysId,
|
||||||
|
ticketType,
|
||||||
|
endpoint: url
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
logError(error, `ERRO: Falha ao adicionar comentario ao ticket SN (sysId: ${sysId})`);
|
logError(error, `ERRO: Falha ao adicionar comentario ao ticket SN (sysId: ${sysId})`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user