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.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
2020-11-12 13:24:45 +01: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-02-05 00:17:49 +01:00
|
|
|
export const searchTableData = async (tableId, search, pageSize) => {
|
2021-02-01 22:02:54 +01:00
|
|
|
const rows = await API.post({
|
|
|
|
url: `/api/${tableId}/rows/search`,
|
|
|
|
body: {
|
|
|
|
query: search,
|
2021-02-05 00:17:49 +01:00
|
|
|
pageSize,
|
2021-02-01 22:02:54 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
return await enrichRows(rows, tableId)
|
|
|
|
}
|