|
|
|
@ -6,11 +6,11 @@ export default async function fetchData(datasource, store) { |
|
|
|
if (name) { |
|
|
|
let rows = [] |
|
|
|
if (type === "table") { |
|
|
|
rows = fetchTableData() |
|
|
|
rows = await fetchTableData() |
|
|
|
} else if (type === "view") { |
|
|
|
rows = fetchViewData() |
|
|
|
rows = await fetchViewData() |
|
|
|
} else if (type === "link") { |
|
|
|
rows = fetchLinkedRowsData() |
|
|
|
rows = await fetchLinkedRowsData() |
|
|
|
} |
|
|
|
|
|
|
|
// Fetch table schema so we can check for linked rows
|
|
|
|
@ -19,8 +19,15 @@ export default async function fetchData(datasource, store) { |
|
|
|
const keys = Object.keys(table.schema) |
|
|
|
rows.forEach(row => { |
|
|
|
for (let key of keys) { |
|
|
|
if (table.schema[key].type === "link") { |
|
|
|
const type = table.schema[key].type |
|
|
|
if (type === "link") { |
|
|
|
row[`${key}_count`] = Array.isArray(row[key]) ? row[key].length : 0 |
|
|
|
} else if (type === "attachment") { |
|
|
|
let url = null |
|
|
|
if (Array.isArray(row[key]) && row[key][0] != null) { |
|
|
|
url = row[key][0].url |
|
|
|
} |
|
|
|
row[`${key}_first`] = url |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|