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:
parent
23e134e7a3
commit
8363bde237
@ -29,6 +29,9 @@ HUBSOFT_DATABASE_NAME=hubsoft
|
||||
HUBSOFT_DATABASE_USER=
|
||||
HUBSOFT_DATABASE_PASSWORD=
|
||||
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)
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ node_modules/
|
||||
logs/
|
||||
.env.development
|
||||
.env.production
|
||||
.idea/
|
||||
@ -6,6 +6,7 @@ const { logError } = require('../../../../shared/utils/logger.js')
|
||||
async function getTicketsByTipo({
|
||||
tipoAtendimento,
|
||||
usuarioAbertura = null,
|
||||
usuariosResponsaveisIds = null,
|
||||
watermark = null
|
||||
}) {
|
||||
try {
|
||||
@ -81,6 +82,23 @@ async function getTicketsByTipo({
|
||||
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) {
|
||||
query += ` AND a.data_cadastro > $${paramIndex++}`;
|
||||
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) {
|
||||
try {
|
||||
|
||||
|
||||
@ -41,6 +41,10 @@ async function getMundialeTickets(watermark) {
|
||||
async function getImplantacaoTickets(watermark) {
|
||||
return hubsoftTicketsRepo.getTicketsByTipo({
|
||||
tipoAtendimento: TYPES.IMPLANTACAO,
|
||||
usuariosResponsaveisIds: parseCsvNumberEnv(
|
||||
process.env.HUBSOFT_IMPLANTACAO_RESPONSAVEL_USER_IDS,
|
||||
[142]
|
||||
),
|
||||
watermark
|
||||
});
|
||||
}
|
||||
@ -48,6 +52,10 @@ async function getImplantacaoTickets(watermark) {
|
||||
async function getCancelamentoTickets(watermark) {
|
||||
return hubsoftTicketsRepo.getTicketsByTipo({
|
||||
tipoAtendimento: TYPES.CANCELAMENTO,
|
||||
usuariosResponsaveisIds: parseCsvNumberEnv(
|
||||
process.env.HUBSOFT_CANCELAMENTO_RESPONSAVEL_USER_IDS,
|
||||
[142]
|
||||
),
|
||||
watermark
|
||||
});
|
||||
}
|
||||
@ -62,6 +70,10 @@ async function getSacTickets(watermark) {
|
||||
async function getTrocaTTickets(watermark) {
|
||||
return hubsoftTicketsRepo.getTicketsByTipo({
|
||||
tipoAtendimento: TYPES.TITULARIDADE,
|
||||
usuariosResponsaveisIds: parseCsvNumberEnv(
|
||||
process.env.HUBSOFT_TITULARIDADE_RESPONSAVEL_USER_IDS,
|
||||
[142]
|
||||
),
|
||||
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 = {
|
||||
// watermark
|
||||
|
||||
@ -5,7 +5,7 @@ const repository = require('../repositories/ticket.repository.js')
|
||||
async function resolveEntityId(ticketData) {
|
||||
|
||||
const entityByService = await repository.getEntitiesByService(
|
||||
ticketData.codigo_clasiente,
|
||||
ticketData.codigo_cliente,
|
||||
ticketData.codigo_servico
|
||||
);
|
||||
|
||||
|
||||
@ -22,31 +22,31 @@ async function syncTicketsUseCase() {
|
||||
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 Implantacao 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)
|
||||
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)
|
||||
await trocaTitularidadeService.saveHubGlpi(trocaTitularidade)
|
||||
|
||||
const allFetchedTickets = [
|
||||
...mundiale,
|
||||
//...implantacao,
|
||||
//...cancelamento,
|
||||
...implantacao,
|
||||
...cancelamento,
|
||||
//...sac,
|
||||
//...trocaTitularidade
|
||||
...trocaTitularidade
|
||||
]
|
||||
|
||||
const newWaterMark = resolveNewWatermark(allFetchedTickets, waterMark)
|
||||
@ -83,10 +83,10 @@ async function syncTicketsUseCase() {
|
||||
function resolveTicketService(type) {
|
||||
const map = {
|
||||
MUNDIALE: mundialeService,
|
||||
//IMPLANTACAO: implantacaoService,
|
||||
//CANCELAMENTO: cancelamentoService,
|
||||
IMPLANTACAO: implantacaoService,
|
||||
CANCELAMENTO: cancelamentoService,
|
||||
//SAC: sacService, //TODO
|
||||
//TITULARIDADE: trocaTitularidadeService
|
||||
TITULARIDADE: trocaTitularidadeService
|
||||
}
|
||||
|
||||
return map[type]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user