fix: prevent UPSERT from squashing historical data by generating a composite fallback order ID
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m2s

This commit is contained in:
Cauê Faleiros
2026-05-20 15:03:39 -03:00
parent 84ea094d54
commit d862145522

View File

@@ -174,7 +174,9 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
for (const item of payload) { for (const item of payload) {
// Handle potential missing fields gracefully // 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 = [ const values = [
item.Nome_Cliente || 'Unknown', item.Nome_Cliente || 'Unknown',