first commit
Some checks failed
Build and Deploy / build-and-push (push) Failing after 4m14s

This commit is contained in:
Cauê Faleiros
2026-04-09 09:45:02 -03:00
commit c687fd2bd1
12 changed files with 305 additions and 0 deletions

40
dist/controllers/webhook.controller.js vendored Normal file
View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleTinyOrderUpdate = void 0;
const n8n_service_1 = require("../services/n8n.service");
const handleTinyOrderUpdate = async (req, res) => {
try {
let payload = req.body;
// Parse 'dados' if it comes as a JSON string
if (typeof payload.dados === 'string') {
try {
payload.dados = JSON.parse(payload.dados);
}
catch (e) {
console.error('Could not parse "dados" as JSON string.', e);
}
}
console.log('Received webhook from Tiny:', JSON.stringify(payload, null, 2));
// Acknowledge Tiny immediately
res.status(200).send('OK');
if (!payload || Object.keys(payload).length === 0) {
console.warn('Received empty payload from Tiny webhook.');
return;
}
const transformedData = {
source: 'tiny_webhook_middleware',
event: payload.tipo || 'atualizacao_pedido',
dados: payload.dados,
raw_payload: payload
};
// Forward to n8n asynchronously
await (0, n8n_service_1.sendToN8n)(transformedData);
}
catch (error) {
console.error('Error handling Tiny webhook:', error);
if (!res.headersSent) {
res.status(500).json({ error: 'Internal server error processing webhook.' });
}
}
};
exports.handleTinyOrderUpdate = handleTinyOrderUpdate;