FEAT: Adicionado variáveis de ambiente para definir os responsáveis por implantação, cancelamento e titularidade no HubSoft

- Adicionadas as seguintes variáveis de ambiente no arquivo .env.development:
  - HUBSOFT_IMPLANTACAO_RESPONSAVEL_USER_IDS: IDs dos usuários responsáveis pela implantação no HubSoft.
  - HUBSOFT_CANCELAMENTO_RESPONSAVEL_USER_IDS: IDs dos usuários responsáveis pelo cancelamento no HubSoft.
  - HUBSOFT_TITULARIDADE_RESPONSAVEL_USER_IDS: IDs dos usuários responsáveis pela titularidade no HubSoft.
- Atualizadas as implementações relacionadas à implantação, cancelamento e titularidade para utilizar as novas variáveis de ambiente e garantir que as ações sejam atribuídas aos usuários corretos.
This commit is contained in:
Rafael Alves Lopes 2026-04-30 16:41:28 -03:00
parent 23e134e7a3
commit 8363bde237
6 changed files with 67 additions and 16 deletions

View File

@ -29,6 +29,9 @@ HUBSOFT_DATABASE_NAME=hubsoft
HUBSOFT_DATABASE_USER= HUBSOFT_DATABASE_USER=
HUBSOFT_DATABASE_PASSWORD= HUBSOFT_DATABASE_PASSWORD=
HUBSOFT_MUNDIALE_USER_ID=248 HUBSOFT_MUNDIALE_USER_ID=248
HUBSOFT_IMPLANTACAO_RESPONSAVEL_USER_IDS=142
HUBSOFT_CANCELAMENTO_RESPONSAVEL_USER_IDS=142
HUBSOFT_TITULARIDADE_RESPONSAVEL_USER_IDS=142
# ============================================================================== # ==============================================================================
# BANCO DE DADOS INTERMEDIÁRIO - HUBGLPI (PostgreSQL - Desenvolvimento) # BANCO DE DADOS INTERMEDIÁRIO - HUBGLPI (PostgreSQL - Desenvolvimento)

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
logs/ logs/
.env.development .env.development
.env.production .env.production
.idea/

View File

@ -6,6 +6,7 @@ const { logError } = require('../../../../shared/utils/logger.js')
async function getTicketsByTipo({ async function getTicketsByTipo({
tipoAtendimento, tipoAtendimento,
usuarioAbertura = null, usuarioAbertura = null,
usuariosResponsaveisIds = null,
watermark = null watermark = null
}) { }) {
try { try {
@ -81,6 +82,23 @@ async function getTicketsByTipo({
params.push(usuarioAbertura); params.push(usuarioAbertura);
} }
const responsibleUserIds = normalizeUserIds(usuariosResponsaveisIds);
if (responsibleUserIds.length) {
const responsibleIdsParam = paramIndex++;
query += `
AND EXISTS (
SELECT 1
FROM atendimento_usuario_responsavel AS aur
WHERE aur.id_atendimento = a.id_atendimento
AND aur.id_usuario = ANY($${responsibleIdsParam}::int[])
)
`;
params.push(responsibleUserIds);
}
if (watermark) { if (watermark) {
query += ` AND a.data_cadastro > $${paramIndex++}`; query += ` AND a.data_cadastro > $${paramIndex++}`;
params.push(watermark); params.push(watermark);
@ -95,6 +113,12 @@ async function getTicketsByTipo({
} }
} }
function normalizeUserIds(values) {
return (values || [])
.map(value => Number(value))
.filter(Number.isInteger);
}
async function getTicketsClosedSince(thresholdDate) { async function getTicketsClosedSince(thresholdDate) {
try { try {

View File

@ -41,6 +41,10 @@ async function getMundialeTickets(watermark) {
async function getImplantacaoTickets(watermark) { async function getImplantacaoTickets(watermark) {
return hubsoftTicketsRepo.getTicketsByTipo({ return hubsoftTicketsRepo.getTicketsByTipo({
tipoAtendimento: TYPES.IMPLANTACAO, tipoAtendimento: TYPES.IMPLANTACAO,
usuariosResponsaveisIds: parseCsvNumberEnv(
process.env.HUBSOFT_IMPLANTACAO_RESPONSAVEL_USER_IDS,
[142]
),
watermark watermark
}); });
} }
@ -48,6 +52,10 @@ async function getImplantacaoTickets(watermark) {
async function getCancelamentoTickets(watermark) { async function getCancelamentoTickets(watermark) {
return hubsoftTicketsRepo.getTicketsByTipo({ return hubsoftTicketsRepo.getTicketsByTipo({
tipoAtendimento: TYPES.CANCELAMENTO, tipoAtendimento: TYPES.CANCELAMENTO,
usuariosResponsaveisIds: parseCsvNumberEnv(
process.env.HUBSOFT_CANCELAMENTO_RESPONSAVEL_USER_IDS,
[142]
),
watermark watermark
}); });
} }
@ -62,6 +70,10 @@ async function getSacTickets(watermark) {
async function getTrocaTTickets(watermark) { async function getTrocaTTickets(watermark) {
return hubsoftTicketsRepo.getTicketsByTipo({ return hubsoftTicketsRepo.getTicketsByTipo({
tipoAtendimento: TYPES.TITULARIDADE, tipoAtendimento: TYPES.TITULARIDADE,
usuariosResponsaveisIds: parseCsvNumberEnv(
process.env.HUBSOFT_TITULARIDADE_RESPONSAVEL_USER_IDS,
[142]
),
watermark watermark
}); });
} }
@ -130,6 +142,17 @@ async function sendHubglpiMessage(hubId, message) {
}); });
} }
function parseCsvNumberEnv(value, fallback = []) {
if (!value) return fallback;
const parsed = value
.split(',')
.map(item => Number(item.trim()))
.filter(Number.isInteger);
return parsed.length ? parsed : fallback;
}
module.exports = { module.exports = {
// watermark // watermark

View File

@ -5,7 +5,7 @@ const repository = require('../repositories/ticket.repository.js')
async function resolveEntityId(ticketData) { async function resolveEntityId(ticketData) {
const entityByService = await repository.getEntitiesByService( const entityByService = await repository.getEntitiesByService(
ticketData.codigo_clasiente, ticketData.codigo_cliente,
ticketData.codigo_servico ticketData.codigo_servico
); );

View File

@ -22,31 +22,31 @@ async function syncTicketsUseCase() {
const mundiale = await mundialeService.fetchNew(waterMark) const mundiale = await mundialeService.fetchNew(waterMark)
logInfo(`[USECASE] ${mundiale.length} tickets Mundiale encontrados`) logInfo(`[USECASE] ${mundiale.length} tickets Mundiale encontrados`)
//const implantacao = await implantacaoService.fetchNew(waterMark) const implantacao = await implantacaoService.fetchNew(waterMark)
//logInfo(`[USECASE] ${implantacao.length} tickets Implantação encontrados`) logInfo(`[USECASE] ${implantacao.length} tickets Implantacao encontrados`)
//const cancelamento = await cancelamentoService.fetchNew(waterMark) const cancelamento = await cancelamentoService.fetchNew(waterMark)
//logInfo(`[USECASE] ${cancelamento.length} tickets Cancelamento encontrados`) logInfo(`[USECASE] ${cancelamento.length} tickets Cancelamento encontrados`)
//const sac = await sacService.fetchNew(waterMark) //TODO //const sac = await sacService.fetchNew(waterMark) //TODO
//logInfo(`[USECASE] ${sac.length} tickets SAC encontrados`) //logInfo(`[USECASE] ${sac.length} tickets SAC encontrados`)
//const trocaTitularidade = await trocaTitularidadeService.fetchNew(waterMark) //TODO const trocaTitularidade = await trocaTitularidadeService.fetchNew(waterMark)
//logInfo(`[USECASE] ${trocaTitularidade.length} tickets Troca de Titularidade encontrados`) logInfo(`[USECASE] ${trocaTitularidade.length} tickets Troca de Titularidade encontrados`)
await mundialeService.saveHubGlpi(mundiale) await mundialeService.saveHubGlpi(mundiale)
//await implantacaoService.saveHubGlpi(implantacao) await implantacaoService.saveHubGlpi(implantacao)
//await cancelamentoService.saveHubGlpi(cancelamento) await cancelamentoService.saveHubGlpi(cancelamento)
//await sacService.saveHubGlpi(sac) //TODO //await sacService.saveHubGlpi(sac) //TODO
//await trocaTitularidadeService.saveHubGlpi(trocaTitularidade) await trocaTitularidadeService.saveHubGlpi(trocaTitularidade)
const allFetchedTickets = [ const allFetchedTickets = [
...mundiale, ...mundiale,
//...implantacao, ...implantacao,
//...cancelamento, ...cancelamento,
//...sac, //...sac,
//...trocaTitularidade ...trocaTitularidade
] ]
const newWaterMark = resolveNewWatermark(allFetchedTickets, waterMark) const newWaterMark = resolveNewWatermark(allFetchedTickets, waterMark)
@ -83,10 +83,10 @@ async function syncTicketsUseCase() {
function resolveTicketService(type) { function resolveTicketService(type) {
const map = { const map = {
MUNDIALE: mundialeService, MUNDIALE: mundialeService,
//IMPLANTACAO: implantacaoService, IMPLANTACAO: implantacaoService,
//CANCELAMENTO: cancelamentoService, CANCELAMENTO: cancelamentoService,
//SAC: sacService, //TODO //SAC: sacService, //TODO
//TITULARIDADE: trocaTitularidadeService TITULARIDADE: trocaTitularidadeService
} }
return map[type] return map[type]