diff --git a/src/infra/api/hubsoft.client.js b/src/infra/api/hubsoft.client.js index d18bae3..1552c4c 100644 --- a/src/infra/api/hubsoft.client.js +++ b/src/infra/api/hubsoft.client.js @@ -14,9 +14,6 @@ async function sendHubsoftMessage(atendimentoId, mensagem) { const url = `${hubsoft.atendimentosUrl}adicionar_mensagem/${atendimentoId}` const payload = { mensagem } - console.log('URL:', url) - console.log('Payload:', payload) - try { logInfo(`Enviando mensagem para atendimento HubSoft ${atendimentoId}`) @@ -38,6 +35,36 @@ async function sendHubsoftMessage(atendimentoId, mensagem) { } } +/** + * Encerra um atendimento no HubSoft + */ +async function close(atendimentoId, mensagem) { +try { + const token = await getAuthToken(); + + const response = await axios.put(`${hubsoft.atendimentosUrl}${atendimentoId}`, { + "fechar_atendimento": true, + "parametros_fechamento": { + "descricao_fechamento": mensagem + } + }, + { + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + } + }); + return response.data; + } catch (error) { + logError(`Erro ao fechar atendimento ID ${atendimentoId}:`, error.response ? error.response.data : error.message); + throw error; + } +}; + + + + module.exports = { - sendHubsoftMessage + sendHubsoftMessage, + close } diff --git a/src/modules/comments/useCases/syncGlpiCommentToHub.usecase.js b/src/modules/comments/useCases/syncGlpiCommentToHub.usecase.js index 2aa4861..a96160b 100644 --- a/src/modules/comments/useCases/syncGlpiCommentToHub.usecase.js +++ b/src/modules/comments/useCases/syncGlpiCommentToHub.usecase.js @@ -2,7 +2,7 @@ const repository = require('../repositories/comment.repository') const { sanitizeGLPIComment } = require('../../../shared/utils/commentSanitizer') -const { logInfo, logError, logWarn } = require('../../../shared/utils/logger') +const { logInfo, logError, logWarning } = require('../../../shared/utils/logger') async function sync({ glpiTicketId, glpiMessageId, rawContent }) { logInfo(`[COMMENTS][GLPI->HUB] Ticket ${glpiTicketId}`) @@ -10,7 +10,7 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) { try { const syncRecord = await repository.getSyncByGlpiId(glpiTicketId) if (!syncRecord?.hubsoft_ticket_id) { - logWarn('[COMMENTS][GLPI->HUB] Ticket sem vĂ­nculo com Hubsoft') + logWarning('[COMMENTS][GLPI->HUB] Ticket sem vĂ­nculo com Hubsoft') return } @@ -31,13 +31,18 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) { content ) + + + await repository.insertSyncComment({ - source: 'glpi', + syncDataId: syncRecord.id, + sourceSystem: 'glpi', sourceCommentId: glpiMessageId, destinationCommentId: hubsoftMessageId, hubsoftTicketId: syncRecord.hubsoft_ticket_id, glpiTicketId, content, + author: 'glpi-user', status: 'synced' })