Update app.js

This commit is contained in:
oliver
2026-06-14 20:13:23 -03:00
parent cc1bff3be0
commit 0502073bd9
+5 -12
View File
@@ -1375,18 +1375,11 @@ async function crmLoadRecords() {
}); });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`); if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
const json = await res.json(); const json = await res.json();
// Normalise: response may be [[{...},...]] or [{...},...] or {response:[...]} // Shape: {data: [{...}, ...]}
let data; let data = json?.data ?? json?.response ?? json;
if (Array.isArray(json)) { // If the outer result wraps in an extra array like [{data:[...]}] handle that too
if (json.length > 0 && Array.isArray(json[0])) { if (Array.isArray(data) && data.length > 0 && data[0]?.data) {
data = json[0]; data = data[0].data;
} else {
data = json;
}
} else if (json && json.response) {
data = json.response;
} else {
data = [];
} }
crmRecords = Array.isArray(data) ? data : []; crmRecords = Array.isArray(data) ? data : [];
crmRender(); crmRender();