// src/services/servicenowService.js const axios = require('axios'); const { logError, logInfo } = require('../utils/logger'); // Configurações da API do ServiceNow const serviceNowConfig = { baseURL: process.env.SERVICENOW_BASE_URL, auth: { username: process.env.SERVICENOW_USERNAME, password: process.env.SERVICENOW_PASSWORD, }, }; // Função para buscar um ticket pelo ID const getTicketById = async (ticketId) => { try { const response = await axios.get(`/api/now/table/ticket/${ticketId}`, serviceNowConfig); logInfo(`Ticket ${ticketId} fetched successfully.`); return response.data.result; } catch (error) { logError(`Error fetching ticket ${ticketId}: ${error.message}`); throw error; } }; // Função para criar um novo ticket no ServiceNow const createTicket = async (ticketData) => { try { const response = await axios.post('/api/now/table/ticket', ticketData, serviceNowConfig); logInfo(`Ticket created successfully with ID: ${response.data.result.sys_id}`); return response.data.result; } catch (error) { logError(`Error creating ticket: ${error.message}`); throw error; } }; // Função para atualizar um ticket existente const updateTicket = async (ticketId, ticketData) => { try { const response = await axios.put(`/api/now/table/ticket/${ticketId}`, ticketData, serviceNowConfig); logInfo(`Ticket ${ticketId} updated successfully.`); return response.data.result; } catch (error) { logError(`Error updating ticket ${ticketId}: ${error.message}`); throw error; } }; // Exporta as funções para uso em outros módulos module.exports = { getTicketById, createTicket, updateTicket, };