2022-01-20 10:40:53 +01:00
|
|
|
export const buildTableEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Fetches a table definition.
|
|
|
|
* Since definitions cannot change at runtime, the result is cached.
|
|
|
|
*/
|
|
|
|
fetchTableDefinition: async tableId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/tables/${tableId}`,
|
|
|
|
cache: true,
|
|
|
|
})
|
|
|
|
},
|
2020-11-12 10:07:09 +01:00
|
|
|
|
2022-01-20 10:40:53 +01:00
|
|
|
/**
|
|
|
|
* Fetches all rows from a table.
|
|
|
|
*/
|
|
|
|
fetchTableData: async tableId => {
|
|
|
|
return await API.get({ url: `/api/${tableId}/rows` })
|
|
|
|
},
|
2021-05-26 18:38:49 +02:00
|
|
|
|
2022-01-20 10:40:53 +01:00
|
|
|
/**
|
|
|
|
* Searches a table using Lucene.
|
|
|
|
*/
|
|
|
|
searchTable: async ({
|
|
|
|
tableId,
|
|
|
|
query,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
|
|
|
sortType,
|
|
|
|
paginate,
|
|
|
|
}) => {
|
|
|
|
if (!tableId || !query) {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
}
|
2021-05-26 18:38:49 +02:00
|
|
|
}
|
2022-01-20 10:40:53 +01:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/${tableId}/search`,
|
|
|
|
body: {
|
|
|
|
query,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
|
|
|
sortType,
|
|
|
|
paginate,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|