Update app.js

This commit is contained in:
oliver
2026-06-09 14:09:55 -03:00
parent fbd620074b
commit fc90204d97
+4 -4
View File
@@ -1131,13 +1131,13 @@ async function loadInvoices() {
if (!res.ok) throw new Error(`HTTP ${res.status}`); if (!res.ok) throw new Error(`HTTP ${res.status}`);
let data = await res.json(); let data = await res.json();
dbg("\u2190 Invoices", data); dbg("\u2190 Invoices", data);
// unwrap n8n envelope: [{json:{...}}] → [{...}] // unwrap envelope: {data:[...]} or [{json:{...}}] or plain array
if (Array.isArray(data)) { if (data && !Array.isArray(data) && Array.isArray(data.data)) {
data = data.data;
} else if (Array.isArray(data)) {
data = data.map((item) => data = data.map((item) =>
item && typeof item === "object" && "json" in item ? item.json : item, item && typeof item === "object" && "json" in item ? item.json : item,
); );
} else if (data && typeof data === "object" && "json" in data) {
data = [data.json];
} else { } else {
data = []; data = [];
} }