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.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @param tableId the ID of the table to fetch
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
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.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @param tableId the ID of the table for fetch
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
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.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @param tableId the ID of the table to search
|
|
|
|
* @param query the lucene search query
|
|
|
|
* @param bookmark the current pagination bookmark
|
|
|
|
* @param limit the number of rows to retrieve
|
|
|
|
* @param sort the field to sort by
|
|
|
|
* @param sortOrder the order to sort by
|
|
|
|
* @param sortType the type to sort by, either numerically or alphabetically
|
|
|
|
* @param paginate whether to paginate the data
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-01-24 11:44:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports data into an existing table
|
|
|
|
* @param tableId the table ID to import to
|
2023-05-25 19:05:07 +02:00
|
|
|
* @param rows the data import object
|
|
|
|
* @param identifierFields column names to be used as keys for overwriting existing rows
|
2022-01-24 11:44:37 +01:00
|
|
|
*/
|
2023-05-25 19:05:07 +02:00
|
|
|
importTableData: async ({ tableId, rows, identifierFields }) => {
|
2022-01-24 11:44:37 +01:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/tables/${tableId}/import`,
|
|
|
|
body: {
|
2023-01-17 16:07:52 +01:00
|
|
|
rows,
|
2023-05-25 19:05:07 +02:00
|
|
|
identifierFields,
|
2022-01-24 11:44:37 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2023-01-17 16:07:52 +01:00
|
|
|
csvToJson: async csvString => {
|
2022-01-24 11:44:37 +01:00
|
|
|
return await API.post({
|
2023-01-17 16:07:52 +01:00
|
|
|
url: "/api/convert/csvToJson",
|
2022-01-24 11:44:37 +01:00
|
|
|
body: {
|
|
|
|
csvString,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2023-09-26 18:01:30 +02:00
|
|
|
|
2022-01-24 13:37:22 +01:00
|
|
|
/**
|
2023-09-26 18:01:30 +02:00
|
|
|
* Gets a list of tables.
|
2022-01-24 13:37:22 +01:00
|
|
|
*/
|
|
|
|
getTables: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/tables",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-09-26 18:01:30 +02:00
|
|
|
/**
|
|
|
|
* Get a single table based on table ID.
|
|
|
|
*/
|
|
|
|
getTable: async tableId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/tables/${tableId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 13:37:22 +01:00
|
|
|
/**
|
|
|
|
* Saves a table.
|
|
|
|
* @param table the table to save
|
|
|
|
*/
|
|
|
|
saveTable: async table => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/tables",
|
|
|
|
body: table,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a table.
|
|
|
|
* @param tableId the ID of the table to delete
|
|
|
|
* @param tableRev the rev of the table to delete
|
|
|
|
*/
|
|
|
|
deleteTable: async ({ tableId, tableRev }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/tables/${tableId}/${tableRev}`,
|
|
|
|
})
|
|
|
|
},
|
2023-01-17 16:07:52 +01:00
|
|
|
validateNewTableImport: async ({ rows, schema }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/tables/validateNewTableImport",
|
|
|
|
body: {
|
|
|
|
rows,
|
|
|
|
schema,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
validateExistingTableImport: async ({ rows, tableId }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/tables/validateExistingTableImport",
|
|
|
|
body: {
|
|
|
|
rows,
|
|
|
|
tableId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-01-20 10:40:53 +01:00
|
|
|
})
|