FIX: API traz WebHook do GLPI como JSON, configurado request que era carregada como RAW
This commit is contained in:
parent
140212f321
commit
69798e84e4
@ -4,7 +4,7 @@ const router = require('./routes.js')
|
||||
function createApp() {
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.json({ type: '*/*' }));
|
||||
app.use('/api', router);
|
||||
|
||||
return app;
|
||||
|
||||
@ -2,11 +2,30 @@ const ticketService = require('../services/ticketService.js');
|
||||
|
||||
const closeTicket = async (req, res) => {
|
||||
try {
|
||||
const closingTicket = await ticketService.fechaTicket(req);
|
||||
res.status(200).json(closingTicket);
|
||||
let rawData = '';
|
||||
|
||||
req.on('data', chunk => {
|
||||
rawData += chunk;
|
||||
});
|
||||
|
||||
req.on('end', async () => {
|
||||
let bodyRequest;
|
||||
try {
|
||||
bodyRequest = JSON.parse(rawData);
|
||||
} catch (err) {
|
||||
console.error('Erro ao parsear JSON:', err);
|
||||
bodyRequest = {};
|
||||
}
|
||||
|
||||
console.log('Fechando ticket com os dados:', bodyRequest);
|
||||
const closingTicket = await ticketService.fechaTicket(bodyRequest);
|
||||
res.status(200).json(closingTicket);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { closeTicket };
|
||||
@ -1,66 +1,7 @@
|
||||
|
||||
|
||||
const fechaTicket = async (req) => {
|
||||
// Lógica para fechar o ticket no GLPI
|
||||
// Exemplo fictício:
|
||||
|
||||
// Exemplo JSON que vem na requisição:
|
||||
// {
|
||||
// "item": {
|
||||
// "id": 27779,
|
||||
// "itemtype": "Ticket",
|
||||
// "items_id": 34213,
|
||||
// "content": "<p>Closing Task<\/p>",
|
||||
// "user": {
|
||||
// "id": 917,
|
||||
// "name": "rafael.lopes"
|
||||
// },
|
||||
// "user_editor": null
|
||||
// },
|
||||
// "event": "new",
|
||||
// "parent_item": {
|
||||
// "id": 34213,
|
||||
// "name": "TESTE",
|
||||
// "content": "<p>teste<\/p>",
|
||||
// "is_deleted": false,
|
||||
// "urgency": 3,
|
||||
// "impact": 3,
|
||||
// "priority": 3,
|
||||
// "actiontime": 0,
|
||||
// "date_creation": "2025-11-03T16:26:12-03:00",
|
||||
// "date_mod": "2025-11-05T10:44:03-03:00",
|
||||
// "date": "2025-11-03T16:26:12-03:00",
|
||||
// "type": 1,
|
||||
// "external_id": "",
|
||||
// "status": {
|
||||
// "id": 5,
|
||||
// "name": "Solucionado"
|
||||
// },
|
||||
// "category": {
|
||||
// "id": 5814,
|
||||
// "name": "HubSoft"
|
||||
// },
|
||||
// "location": null,
|
||||
// "request_type": {
|
||||
// "id": 1,
|
||||
// "name": "Helpdesk"
|
||||
// },
|
||||
// "entity": {
|
||||
// "id": 0,
|
||||
// "name": "Contratos Ativos",
|
||||
// "completename": "Contratos Ativos"
|
||||
// },
|
||||
// "team": []
|
||||
// }
|
||||
// }
|
||||
|
||||
// armazenar o body numa const
|
||||
|
||||
const bodyRequest = req.body;
|
||||
|
||||
return {bodyRequest};
|
||||
|
||||
|
||||
// HUBXGLPI/src/services/ticketService.js
|
||||
const fechaTicket = async (bodyRequest) => {
|
||||
console.log('Ticket recebido no service:', bodyRequest);
|
||||
return { bodyRequest };
|
||||
}
|
||||
|
||||
module.exports = { fechaTicket };
|
||||
Loading…
Reference in New Issue
Block a user