2020-11-12 10:07:09 +01:00
|
|
|
import api from "./api"
|
2020-11-12 13:24:45 +01:00
|
|
|
import { enrichRows } from "./rows"
|
2020-11-12 10:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches related rows for a certain field of a certain row.
|
|
|
|
*/
|
|
|
|
export const fetchRelationshipData = async ({ tableId, rowId, fieldName }) => {
|
2020-11-19 14:50:20 +01:00
|
|
|
if (!tableId || !rowId || !fieldName) {
|
2020-11-12 10:07:09 +01:00
|
|
|
return []
|
|
|
|
}
|
|
|
|
const response = await api.get({ url: `/api/${tableId}/${rowId}/enrich` })
|
2020-11-12 13:24:45 +01:00
|
|
|
const rows = response[fieldName] || []
|
|
|
|
return await enrichRows(rows, tableId)
|
2020-11-12 10:07:09 +01:00
|
|
|
}
|