2022-01-20 10:40:53 +01:00
|
|
|
export const buildRelationshipEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Fetches related rows for a certain field of a certain row.
|
|
|
|
*/
|
|
|
|
fetchRelationshipData: async ({ tableId, rowId, fieldName }) => {
|
2022-01-24 11:44:37 +01:00
|
|
|
if (!tableId || !rowId) {
|
2022-01-20 10:40:53 +01:00
|
|
|
return []
|
|
|
|
}
|
|
|
|
const response = await API.get({ url: `/api/${tableId}/${rowId}/enrich` })
|
2022-01-24 11:44:37 +01:00
|
|
|
if (!fieldName) {
|
|
|
|
return response || []
|
|
|
|
} else {
|
|
|
|
return response[fieldName] || []
|
|
|
|
}
|
2022-01-20 10:40:53 +01:00
|
|
|
},
|
|
|
|
})
|