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() {
|
function createApp() {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json({ type: '*/*' }));
|
||||||
app.use('/api', router);
|
app.use('/api', router);
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
|||||||
@ -2,11 +2,30 @@ const ticketService = require('../services/ticketService.js');
|
|||||||
|
|
||||||
const closeTicket = async (req, res) => {
|
const closeTicket = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const closingTicket = await ticketService.fechaTicket(req);
|
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);
|
res.status(200).json(closingTicket);
|
||||||
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: error.message });
|
res.status(500).json({ error: error.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = { closeTicket };
|
module.exports = { closeTicket };
|
||||||
@ -1,66 +1,7 @@
|
|||||||
|
// HUBXGLPI/src/services/ticketService.js
|
||||||
|
const fechaTicket = async (bodyRequest) => {
|
||||||
const fechaTicket = async (req) => {
|
console.log('Ticket recebido no service:', bodyRequest);
|
||||||
// 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 };
|
return { bodyRequest };
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { fechaTicket };
|
module.exports = { fechaTicket };
|
||||||
Loading…
Reference in New Issue
Block a user