From d862145522a92f45ea80d6f4890e333096197313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 20 May 2026 15:03:39 -0300 Subject: [PATCH] fix: prevent UPSERT from squashing historical data by generating a composite fallback order ID --- backend/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 324ba0c..2de1afb 100644 --- a/backend/index.js +++ b/backend/index.js @@ -174,7 +174,9 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => { for (const item of payload) { // Handle potential missing fields gracefully - const orderId = item.id || item.ID_Pedido || (item.json && item.json.body && item.json.body.id) || ''; + // If there is no explicit ID, create a composite ID using Name + Date + Value to prevent squashing historical data + const fallbackId = `${item.Nome_Cliente}_${item.Data_Pedido}_${item.Valor_Pedido}`; + const orderId = item.id || item.ID_Pedido || (item.json && item.json.body && item.json.body.id) || fallbackId; const values = [ item.Nome_Cliente || 'Unknown',