2020-11-19 19:39:22 +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 a table definition.
|
|
|
|
* Since definitions cannot change at runtime, the result is cached.
|
|
|
|
*/
|
2021-05-11 12:24:16 +02:00
|
|
|
export const fetchTableDefinition = async tableId => {
|
2020-11-19 19:39:22 +01:00
|
|
|
return await API.get({ url: `/api/tables/${tableId}`, cache: true })
|
2020-11-12 10:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all rows from a table.
|
|
|
|
*/
|
2021-05-11 12:24:16 +02:00
|
|
|
export const fetchTableData = async tableId => {
|
2020-11-19 19:39:22 +01:00
|
|
|
const rows = await API.get({ url: `/api/${tableId}/rows` })
|
2020-11-12 13:24:45 +01:00
|
|
|
return await enrichRows(rows, tableId)
|
2020-11-12 10:07:09 +01:00
|
|
|
}
|
2021-02-01 22:02:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform a mango query against an internal table
|
|
|
|
* @param {String} tableId - id of the table to search
|
|
|
|
* @param {Object} search - Mango Compliant search object
|
2021-03-26 00:42:50 +01:00
|
|
|
* @param {Object} pagination - the pagination controls
|
2021-02-01 22:02:54 +01:00
|
|
|
*/
|
2021-02-08 18:44:44 +01:00
|
|
|
export const searchTableData = async ({ tableId, search, pagination }) => {
|
2021-03-26 00:42:50 +01:00
|
|
|
const output = await API.post({
|
2021-02-01 22:02:54 +01:00
|
|
|
url: `/api/${tableId}/rows/search`,
|
|
|
|
body: {
|
|
|
|
query: search,
|
2021-02-08 18:44:44 +01:00
|
|
|
pagination,
|
2021-02-01 22:02:54 +01:00
|
|
|
},
|
|
|
|
})
|
2021-03-26 00:42:50 +01:00
|
|
|
output.rows = await enrichRows(output.rows, tableId)
|
|
|
|
return output
|
2021-02-01 22:02:54 +01:00
|
|
|
}
|
2021-04-30 17:29:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches a table using Lucene.
|
|
|
|
*/
|
|
|
|
export const searchTable = async ({
|
|
|
|
tableId,
|
|
|
|
query,
|
|
|
|
raw,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
2021-05-11 12:24:16 +02:00
|
|
|
sortType,
|
2021-04-30 17:29:53 +02:00
|
|
|
}) => {
|
|
|
|
if (!tableId || (!query && !raw)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const res = await API.post({
|
|
|
|
url: `/api/search/${tableId}/rows`,
|
|
|
|
body: {
|
|
|
|
query,
|
|
|
|
raw,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
2021-05-11 12:24:16 +02:00
|
|
|
sortType,
|
2021-04-30 17:29:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
rows: await enrichRows(res?.rows, tableId),
|
|
|
|
bookmark: res.bookmark,
|
|
|
|
}
|
|
|
|
}
|