2020-06-13 07:42:55 +12:00
|
|
|
const Router = require("@koa/router")
|
2020-10-10 07:10:28 +13:00
|
|
|
const rowController = require("../controllers/row")
|
2020-06-13 07:42:55 +12:00
|
|
|
const authorized = require("../../middleware/authorized")
|
2020-10-07 07:13:41 +13:00
|
|
|
const usage = require("../../middleware/usageQuota")
|
2021-02-09 06:22:07 +13:00
|
|
|
const {
|
|
|
|
paramResource,
|
|
|
|
paramSubResource,
|
|
|
|
} = require("../../middleware/resourceId")
|
2020-11-12 06:34:15 +13:00
|
|
|
const {
|
|
|
|
PermissionLevels,
|
|
|
|
PermissionTypes,
|
2021-05-15 02:43:41 +12:00
|
|
|
} = require("@budibase/auth/permissions")
|
2020-06-13 07:42:55 +12:00
|
|
|
|
|
|
|
const router = Router()
|
|
|
|
|
|
|
|
router
|
2021-11-26 05:13:19 +13:00
|
|
|
/**
|
|
|
|
* @api {get} /api/:tableId/:rowId/enrich Get an enriched row
|
|
|
|
* @apiName /api/:tableId/:rowId/enrich
|
|
|
|
* @apiGroup rows
|
|
|
|
* @apiPermission table read access
|
|
|
|
* @apiDescription This API is only useful when dealing with rows that have relationships.
|
|
|
|
* Normally when a row is a returned from the API relationships will only have the structure
|
|
|
|
* `{ primaryDisplay: "name", _id: ... }` but this call will return the full related rows
|
|
|
|
* for each relationship instead.
|
|
|
|
*
|
|
|
|
* @apiParam {string} rowId The ID of the row which is to be retrieved and enriched.
|
|
|
|
*
|
|
|
|
* @apiSuccess {object} row The response body will be the enriched row.
|
|
|
|
* @apiError {string} message If the table or row could not be found then an error will be thrown.
|
|
|
|
*/
|
2020-09-30 00:02:06 +13:00
|
|
|
.get(
|
2020-10-10 07:10:28 +13:00
|
|
|
"/api/:tableId/:rowId/enrich",
|
2021-02-09 06:22:07 +13:00
|
|
|
paramSubResource("tableId", "rowId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.fetchEnrichedRow
|
2020-09-30 00:02:06 +13:00
|
|
|
)
|
2021-11-26 05:13:19 +13:00
|
|
|
/**
|
|
|
|
* @api {get} /api/:tableId/rows Get all rows in a table
|
|
|
|
* @apiName /api/:tableId/rows
|
|
|
|
* @apiGroup rows
|
|
|
|
* @apiPermission table read access
|
|
|
|
* @apiDescription This is a deprecated endpoint that should not be used anymore, instead use the search endpoint.
|
|
|
|
* This endpoint gets all of the rows within the specified table - it is not heavily used
|
|
|
|
* due to its lack of support for pagination. With SQL tables this will retrieve up to a limit and then
|
|
|
|
* will simply stop.
|
|
|
|
*
|
|
|
|
* @apiParam {string} tableId The ID of the table to retrieve all rows within.
|
|
|
|
*
|
|
|
|
* @apiSuccess {object[]} rows The response body will be an array of all rows found.
|
|
|
|
* @apiError {string} message If the table could not be found then an error will be thrown.
|
|
|
|
*/
|
2020-06-13 07:42:55 +12:00
|
|
|
.get(
|
2020-10-10 07:10:28 +13:00
|
|
|
"/api/:tableId/rows",
|
2021-02-09 06:22:07 +13:00
|
|
|
paramResource("tableId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
2021-06-16 00:03:55 +12:00
|
|
|
rowController.fetch
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
2021-11-26 05:13:19 +13:00
|
|
|
/**
|
|
|
|
* @api {get} /api/:tableId/rows/:rowId Retrieve a single row
|
|
|
|
* @apiName /api/:tableId/rows/:rowId
|
|
|
|
* @apiGroup rows
|
|
|
|
* @apiPermission table read access
|
|
|
|
* @apiDescription This endpoint retrieves only the specified row. If you wish to retrieve
|
|
|
|
* a row by anything other than its _id field, use the search endpoint.
|
|
|
|
*
|
|
|
|
* @apiParam {string} tableId The ID of the table to retrieve a row from.
|
|
|
|
* @apiParam {string} rowId The ID of the row to retrieve.
|
|
|
|
*
|
|
|
|
* @apiSuccess {object} row The response body will be the row that was found.
|
|
|
|
* @apiError {string} message If the table or row could not be found then an error will be thrown.
|
|
|
|
*/
|
2020-06-13 07:42:55 +12:00
|
|
|
.get(
|
2020-10-10 07:10:28 +13:00
|
|
|
"/api/:tableId/rows/:rowId",
|
2021-02-09 06:22:07 +13:00
|
|
|
paramSubResource("tableId", "rowId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.find
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
2021-11-26 05:13:19 +13:00
|
|
|
/**
|
|
|
|
* @api {post} /api/:tableId/search Search for rows in a table
|
|
|
|
* @apiName /api/:tableId/search
|
|
|
|
* @apiGroup rows
|
|
|
|
* @apiPermission table read access
|
|
|
|
* @apiDescription This is the primary method of accessing rows in Budibase, the data provider
|
|
|
|
* and data UI in the builder are built atop this. All filtering, sorting and pagination is
|
|
|
|
* handled through this, for internal and external (datasource plus, e.g. SQL) tables.
|
|
|
|
*
|
|
|
|
* @apiBody
|
|
|
|
*
|
|
|
|
*/
|
2021-06-15 06:05:39 +12:00
|
|
|
.post(
|
|
|
|
"/api/:tableId/search",
|
|
|
|
paramResource("tableId"),
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
|
|
|
rowController.search
|
|
|
|
)
|
2021-06-22 09:29:32 +12:00
|
|
|
// DEPRECATED - this is an old API, but for backwards compat it needs to be
|
|
|
|
// supported still
|
2021-06-22 09:42:57 +12:00
|
|
|
.post(
|
|
|
|
"/api/search/:tableId/rows",
|
2021-06-22 09:29:32 +12:00
|
|
|
paramResource("tableId"),
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
2021-06-22 09:42:57 +12:00
|
|
|
rowController.search
|
|
|
|
)
|
2020-06-13 07:42:55 +12:00
|
|
|
.post(
|
2020-10-10 07:10:28 +13:00
|
|
|
"/api/:tableId/rows",
|
2021-02-09 06:22:07 +13:00
|
|
|
paramResource("tableId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
2020-10-07 07:13:41 +13:00
|
|
|
usage,
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.save
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
2020-09-10 20:36:14 +12:00
|
|
|
.patch(
|
2021-06-15 06:05:39 +12:00
|
|
|
"/api/:tableId/rows",
|
|
|
|
paramResource("tableId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.patch
|
2020-09-10 20:36:14 +12:00
|
|
|
)
|
2020-06-13 07:42:55 +12:00
|
|
|
.post(
|
2020-10-10 07:10:28 +13:00
|
|
|
"/api/:tableId/rows/validate",
|
2021-02-09 06:22:07 +13:00
|
|
|
paramResource("tableId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.validate
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
|
|
|
.delete(
|
2021-06-12 06:54:47 +12:00
|
|
|
"/api/:tableId/rows",
|
|
|
|
paramResource("tableId"),
|
2020-11-12 06:34:15 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
2020-10-07 07:13:41 +13:00
|
|
|
usage,
|
2020-10-10 07:10:28 +13:00
|
|
|
rowController.destroy
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
|
|
|
|
|
|
|
module.exports = router
|