2022-01-20 10:40:53 +01:00
|
|
|
export const buildRelationshipEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Fetches related rows for a certain field of a certain row.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @param tableId the ID of the table to fetch from
|
|
|
|
* @param rowId the ID of the row to fetch related rows for
|
|
|
|
* @param fieldName the name of the relationship field
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
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
|
|
|
},
|
|
|
|
})
|