Compare commits

..

No commits in common. "e4a736fc59df1d9f2839912a1f719c5196f3911b" and "23e134e7a3abc0982a32d2fa1d953172ed4e7511" have entirely different histories.

7 changed files with 16 additions and 93 deletions

View File

@ -29,9 +29,6 @@ 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)

View File

@ -1,26 +0,0 @@
name: Deploy Production
on:
push:
branches:
- main
jobs:
deploy:
runs-on: vm-prod
steps:
- name: Deploy application
run: |
set -euo pipefail
cd /opt/HUBXGLPI
git fetch origin main
git checkout main
git pull --ff-only origin main
npm ci --omit=dev
pm2 reload ecosystem.config.js --env production || pm2 start ecosystem.config.js --env production
pm2 save

1
.gitignore vendored
View File

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

View File

@ -6,7 +6,6 @@ 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 {
@ -82,23 +81,6 @@ 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);
@ -113,12 +95,6 @@ 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,10 +41,6 @@ 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
}); });
} }
@ -52,10 +48,6 @@ 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
}); });
} }
@ -70,10 +62,6 @@ 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
}); });
} }
@ -142,17 +130,6 @@ 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_cliente, ticketData.codigo_clasiente,
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 Implantacao encontrados`) //logInfo(`[USECASE] ${implantacao.length} tickets Implantação 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) //const trocaTitularidade = await trocaTitularidadeService.fetchNew(waterMark) //TODO
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]