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}`);
const json = await res.json();
// Normalise: response may be [[{...},...]] or [{...},...] or {response:[...]}
let data;
if (Array.isArray(json)) {
if (json.length > 0 && Array.isArray(json[0])) {
data = json[0];
} else {
data = json;
}
} else if (json && json.response) {
data = json.response;
} else {
data = [];
// Shape: {data: [{...}, ...]}
let data = json?.data ?? json?.response ?? json;
// If the outer result wraps in an extra array like [{data:[...]}] handle that too
if (Array.isArray(data) && data.length > 0 && data[0]?.data) {
data = data[0].data;
}
crmRecords = Array.isArray(data) ? data : [];
crmRender();