diff --git a/src/modules/tickets/repositories/ticket.repository.js b/src/modules/tickets/repositories/ticket.repository.js index 63fd175..bb5b66b 100644 --- a/src/modules/tickets/repositories/ticket.repository.js +++ b/src/modules/tickets/repositories/ticket.repository.js @@ -66,27 +66,27 @@ async function getTrocaTTickets(watermark) { }); } -async function insertTicketsHubGlpi(tickets){ +async function insertTicketsHubGlpi(tickets) { return hubglpiTicketsRepo.insertTickets(tickets) } -async function insertSyncDataByIds(ids){ +async function insertSyncDataByIds(ids) { return hubglpiSyncRepo.insertSyncData(ids) } -async function fetchPendingTickets(){ +async function fetchPendingTickets() { return hubglpiTicketsRepo.fetchPendingTickets() } -async function insertTicketGlpi(ticket){ +async function insertTicketGlpi(ticket) { return glpiTicketsRepo.insertTicket(ticket) } -async function getEntitiesByService(codigoCliente, codigoServico){ +async function getEntitiesByService(codigoCliente, codigoServico) { return glpiEntitiesRepo.getEntitiesByService(codigoCliente, codigoServico) } -async function getEntitiesByClient(codigoCliente){ +async function getEntitiesByClient(codigoCliente) { return glpiEntitiesRepo.getEntitiesByClient(codigoCliente) } @@ -98,7 +98,7 @@ const GROUP_BY_TYPE = { SAC: 'NOC' } -async function insertGroupTicket(id, type){ +async function insertGroupTicket(id, type) { const group = GROUP_BY_TYPE[type] || 'NOC' if (group === 'IMPLANTACAO') { @@ -108,11 +108,11 @@ async function insertGroupTicket(id, type){ return glpiGroupsRepo.insertGroupNOC(id) } -async function updateSyncDataCreated(hubId, glpiId){ +async function updateSyncDataCreated(hubId, glpiId) { return hubglpiSyncRepo.updateSyncDataCreated(hubId, glpiId) } -async function sendHubsoftMessage(hubId, message){ +async function sendHubsoftMessage(hubId, message) { return hubsoftApiClient.sendHubsoftMessage(hubId, message) } diff --git a/src/modules/tickets/services/cancelamento.service.js b/src/modules/tickets/services/cancelamento.service.js index 9237aa0..3227ebd 100644 --- a/src/modules/tickets/services/cancelamento.service.js +++ b/src/modules/tickets/services/cancelamento.service.js @@ -16,7 +16,7 @@ async function fetchNew(watermark) { } async function saveHubGlpi(tickets) { - if (!tickets.length) return + if (!tickets.length) return logInfo('[CANCELAMENTO] Inserindo chamados no HubGlpi') await repository.insertTicketsHubGlpi(tickets) logInfo('[CANCELAMENTO] Inserindo dado de sincronia dos chamados') @@ -31,7 +31,7 @@ async function sendToGlpi(ticket) { const resolved = await ticketEntityResolver.resolveEntityId(ticket) logInfo('[CANCELAMENTO] Entidade resolvida') - const payload = cancelamentoGlpiModel.toGlpiPayload(resolved) + const payload = cancelamentoGlpiModel.toGlpiPayload(resolved) logInfo('[CANCELAMENTO] Payload preparado para GLPI', payload) logInfo('[CANCELAMENTO] Inserindo ticket no GLPI', { id_atendimento: ticket.id_atendimento }) @@ -40,7 +40,7 @@ async function sendToGlpi(ticket) { await repository.insertGroupTicket(glpiId, 'CANCELAMENTO') logInfo('[CANCELAMENTO] Grupo associado ao ticket GLPI', { glpiId, group: 'CANCELAMENTO' }) - + await repository.updateSyncDataCreated(ticket.id_atendimento, glpiId) logInfo('[CANCELAMENTO] Dados de sincronização atualizados', { id_atendimento: ticket.id_atendimento, glpiId }) @@ -52,9 +52,9 @@ async function sendToGlpi(ticket) { } module.exports = { - fetchNew, - saveHubGlpi, - sendToGlpi + fetchNew, + saveHubGlpi, + sendToGlpi } /** diff --git a/src/modules/tickets/services/mundiale.service.js b/src/modules/tickets/services/mundiale.service.js index 5c7b7fa..0bf34e3 100644 --- a/src/modules/tickets/services/mundiale.service.js +++ b/src/modules/tickets/services/mundiale.service.js @@ -16,7 +16,7 @@ async function fetchNew(watermark) { } async function saveHubGlpi(tickets) { - if (!tickets.length) return + if (!tickets.length) return logInfo('[MUNDIALE] Inserindo chamados no HubGlpi') await repository.insertTicketsHubGlpi(tickets) logInfo('[MUNDIALE] Inserindo dado de sincronia dos chamados') @@ -40,7 +40,7 @@ async function sendToGlpi(ticket) { await repository.insertGroupTicket(glpiId, 'MUNDIALE') logInfo('[MUNDIALE] Grupo associado ao ticket GLPI', { glpiId, group: 'MUNDIALE' }) - + await repository.updateSyncDataCreated(ticket.id_atendimento, glpiId) logInfo('[MUNDIALE] Dados de sincronização atualizados', { id_atendimento: ticket.id_atendimento, glpiId }) @@ -52,9 +52,9 @@ async function sendToGlpi(ticket) { } module.exports = { - fetchNew, - saveHubGlpi, - sendToGlpi + fetchNew, + saveHubGlpi, + sendToGlpi } /** diff --git a/src/modules/tickets/services/resolveTicketEntity.service.js b/src/modules/tickets/services/resolveTicketEntity.service.js index 3e8d730..e065534 100644 --- a/src/modules/tickets/services/resolveTicketEntity.service.js +++ b/src/modules/tickets/services/resolveTicketEntity.service.js @@ -5,14 +5,14 @@ const repository = require('../repositories/ticket.repository.js') async function resolveEntityId(ticketData) { const entityByService = await repository.getEntitiesByService( - ticketData.codigo_cliente, + ticketData.codigo_clasiente, ticketData.codigo_servico ); if (entityByService) { - return { - ...ticketData, - entities_id: entityByService + return { + ...ticketData, + entities_id: entityByService } } @@ -21,15 +21,15 @@ async function resolveEntityId(ticketData) { ); if (entityByClient) { - return { - ...ticketData, - entities_id: entityByClient + return { + ...ticketData, + entities_id: entityByClient } } - return { - ...ticketData, - entities_id: 0 + return { + ...ticketData, + entities_id: 0 } } diff --git a/src/modules/tickets/useCases/syncTickets.usecase.js b/src/modules/tickets/useCases/syncTickets.usecase.js index cfd6e50..ba71824 100644 --- a/src/modules/tickets/useCases/syncTickets.usecase.js +++ b/src/modules/tickets/useCases/syncTickets.usecase.js @@ -1,7 +1,7 @@ //src/modules/tickes/useCases/syncTickets.usecase.js const notifyTicketCreated = require('../services/ticketNotifications.service.js') -const repository = require ('../repositories/ticket.repository.js') +const repository = require('../repositories/ticket.repository.js') const mundialeService = require('../services/mundiale.service.js') const implantacaoService = require('../services/implantacao.service.js') const cancelamentoService = require('../services/cancelamento.service.js') @@ -22,34 +22,34 @@ async function syncTicketsUseCase() { const waterMark = await repository.getWaterMark() logInfo(`Buscando Tickets novos desde de: ${waterMark}`) - const mundiale = await mundialeService.fetchNew(waterMark) + const mundiale = await mundialeService.fetchNew(waterMark) logInfo(`[USECASE] ${mundiale.length} tickets Mundiale encontrados`) - const implantacao = await implantacaoService.fetchNew(waterMark) - logInfo(`[USECASE] ${implantacao.length} tickets Implantação encontrados`) + //const implantacao = await implantacaoService.fetchNew(waterMark) + //logInfo(`[USECASE] ${implantacao.length} tickets Implantação encontrados`) - const cancelamento = await cancelamentoService.fetchNew(waterMark) - logInfo(`[USECASE] ${cancelamento.length} tickets Cancelamento encontrados`) + //const cancelamento = await cancelamentoService.fetchNew(waterMark) + //logInfo(`[USECASE] ${cancelamento.length} tickets Cancelamento encontrados`) //const sac = await sacService.fetchNew(waterMark) //TODO //logInfo(`[USECASE] ${sac.length} tickets SAC encontrados`) - - const trocaTitularidade = await trocaTitularidadeService.fetchNew(waterMark) //TODO - logInfo(`[USECASE] ${trocaTitularidade.length} tickets Troca de Titularidade encontrados`) - + + //const trocaTitularidade = await trocaTitularidadeService.fetchNew(waterMark) //TODO + //logInfo(`[USECASE] ${trocaTitularidade.length} tickets Troca de Titularidade encontrados`) + await mundialeService.saveHubGlpi(mundiale) - await implantacaoService.saveHubGlpi(implantacao) - await cancelamentoService.saveHubGlpi(cancelamento) + //await implantacaoService.saveHubGlpi(implantacao) + //await cancelamentoService.saveHubGlpi(cancelamento) //await sacService.saveHubGlpi(sac) //TODO - await trocaTitularidadeService.saveHubGlpi(trocaTitularidade) //TODO + //await trocaTitularidadeService.saveHubGlpi(trocaTitularidade) const allFetchedTickets = [ ...mundiale, - ...implantacao, - ...cancelamento, + //...implantacao, + //...cancelamento, //...sac, - ...trocaTitularidade + //...trocaTitularidade ] const newWaterMark = resolveNewWatermark(allFetchedTickets, waterMark) @@ -63,16 +63,16 @@ async function syncTicketsUseCase() { logInfo(`[USECASE] ${pendentes.length} tickets pendentes para envio ao GLPI`) for (const ticket of pendentes) { - try { - const service = resolveTicketService(ticket.ticket_type) - if (!service) continue + try { + const service = resolveTicketService(ticket.ticket_type) + if (!service) continue - const glpiId = await service.sendToGlpi(ticket) - await notifyTicketCreated.notifyTicketCreated(ticket.id_atendimento, glpiId) - } catch (err) { - logError(err, `[USECASE] Falha ao processar ticket ${ticket.id_atendimento}`) + const glpiId = await service.sendToGlpi(ticket) + await notifyTicketCreated.notifyTicketCreated(ticket.id_atendimento, glpiId) + } catch (err) { + logError(err, `[USECASE] Falha ao processar ticket ${ticket.id_atendimento}`) + } } -} } @@ -80,10 +80,10 @@ async function syncTicketsUseCase() { function resolveTicketService(type) { const map = { MUNDIALE: mundialeService, - IMPLANTACAO: implantacaoService, - CANCELAMENTO: cancelamentoService, + //IMPLANTACAO: implantacaoService, + //CANCELAMENTO: cancelamentoService, //SAC: sacService, //TODO - TITULARIDADE: trocaTitularidadeService //TODO + //TITULARIDADE: trocaTitularidadeService } return map[type]