2022-02-18 07:58:09 +13:00
|
|
|
const Router = require("@koa/router")
|
2022-02-19 04:47:15 +13:00
|
|
|
const controller = require("../../controllers/public/rows")
|
2022-02-23 06:38:27 +13:00
|
|
|
const authorized = require("../../../middleware/authorized")
|
|
|
|
const { paramSubResource } = require("../../../middleware/resourceId")
|
|
|
|
const {
|
|
|
|
PermissionLevels,
|
|
|
|
PermissionTypes,
|
|
|
|
} = require("@budibase/backend-core/permissions")
|
2022-02-18 07:58:09 +13:00
|
|
|
|
|
|
|
const router = Router()
|
|
|
|
|
2022-02-23 06:38:27 +13:00
|
|
|
router.use(paramSubResource("tableId", "rowId"))
|
|
|
|
|
2022-02-18 07:58:09 +13:00
|
|
|
/**
|
|
|
|
* @openapi
|
2022-02-18 08:55:37 +13:00
|
|
|
* /tables/{tableId}/rows/search:
|
2022-02-18 07:58:09 +13:00
|
|
|
* post:
|
2022-02-19 04:47:15 +13:00
|
|
|
* summary: Used to search for rows within a table.
|
|
|
|
* tags:
|
|
|
|
* - rows
|
2022-02-18 07:58:09 +13:00
|
|
|
* parameters:
|
2022-02-18 08:55:37 +13:00
|
|
|
* - $ref: '#/components/parameters/tableId'
|
2022-02-19 06:44:08 +13:00
|
|
|
* - $ref: '#/components/parameters/appId'
|
2022-02-18 07:58:09 +13:00
|
|
|
* requestBody:
|
|
|
|
* required: true
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
|
|
|
* type: object
|
|
|
|
* properties:
|
|
|
|
* query:
|
|
|
|
* type: object
|
|
|
|
* properties:
|
|
|
|
* string:
|
|
|
|
* type: object
|
|
|
|
* example:
|
|
|
|
* columnName1: value
|
|
|
|
* columnName2: value
|
|
|
|
* description: A map of field name to the string to search for,
|
|
|
|
* this will look for rows that have a value starting with the
|
|
|
|
* string value.
|
|
|
|
* additionalProperties:
|
|
|
|
* type: string
|
|
|
|
* description: The value to search for in the column.
|
|
|
|
* fuzzy:
|
|
|
|
* type: object
|
|
|
|
* description: A fuzzy search, only supported by internal tables.
|
|
|
|
* range:
|
|
|
|
* type: object
|
|
|
|
* description: Searches within a range, the format of this must be
|
|
|
|
* columnName -> [low, high].
|
2022-02-19 06:44:08 +13:00
|
|
|
* example:
|
|
|
|
* columnName1: [10, 20]
|
2022-02-18 07:58:09 +13:00
|
|
|
* equal:
|
|
|
|
* type: object
|
|
|
|
* description: Searches for rows that have a column value that is
|
|
|
|
* exactly the value set.
|
|
|
|
* notEqual:
|
|
|
|
* type: object
|
|
|
|
* description: Searches for any row which does not contain the specified
|
|
|
|
* column value.
|
|
|
|
* empty:
|
|
|
|
* type: object
|
|
|
|
* description: Searches for rows which do not contain the specified column.
|
|
|
|
* The object should simply contain keys of the column names, these
|
|
|
|
* can map to any value.
|
2022-02-19 06:44:08 +13:00
|
|
|
* example:
|
|
|
|
* columnName1: ""
|
2022-02-18 07:58:09 +13:00
|
|
|
* notEmpty:
|
|
|
|
* type: object
|
|
|
|
* description: Searches for rows which have the specified column.
|
|
|
|
* oneOf:
|
|
|
|
* type: object
|
|
|
|
* description: Searches for rows which have a column value that is any
|
|
|
|
* of the specified values. The format of this must be columnName -> [value1, value2].
|
|
|
|
* paginate:
|
|
|
|
* type: boolean
|
|
|
|
* description: Enables pagination, by default this is disabled.
|
|
|
|
* bookmark:
|
|
|
|
* oneOf:
|
|
|
|
* - type: string
|
|
|
|
* - type: integer
|
|
|
|
* description: If retrieving another page, the bookmark from the previous request must be supplied.
|
|
|
|
* limit:
|
|
|
|
* type: integer
|
|
|
|
* description: The maximum number of rows to return, useful when paginating, for internal tables this
|
|
|
|
* will be limited to 1000, for SQL tables it will be 5000.
|
|
|
|
* sort:
|
|
|
|
* type: object
|
|
|
|
* description: A set of parameters describing the sort behaviour of the search.
|
|
|
|
* properties:
|
|
|
|
* order:
|
|
|
|
* type: string
|
|
|
|
* enum: [ascending, descending]
|
|
|
|
* description: The order of the sort, by default this is ascending.
|
|
|
|
* column:
|
|
|
|
* type: string
|
|
|
|
* description: The name of the column by which the rows will be sorted.
|
|
|
|
* type:
|
|
|
|
* type: string
|
|
|
|
* enum: [string, number]
|
|
|
|
* description: Defines whether the column should be treated as a string
|
|
|
|
* or as numbers when sorting.
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: The response will contain an array of rows that match the search parameters.
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
|
|
|
* type: object
|
|
|
|
* properties:
|
|
|
|
* rows:
|
|
|
|
* description: An array of rows, these will each contain an _id field which can be used
|
|
|
|
* to update or delete them.
|
|
|
|
* type: array
|
|
|
|
* items:
|
|
|
|
* type: object
|
|
|
|
* bookmark:
|
|
|
|
* oneOf:
|
|
|
|
* - type: string
|
|
|
|
* - type: integer
|
2022-02-19 04:47:15 +13:00
|
|
|
* description: If pagination in use, this should be provided.
|
2022-02-18 07:58:09 +13:00
|
|
|
* hasNextPage:
|
|
|
|
* description: If pagination in use, this will determine if there is another page to fetch.
|
|
|
|
* type: boolean
|
2022-02-19 06:44:08 +13:00
|
|
|
* examples:
|
|
|
|
* search:
|
2022-02-23 03:10:01 +13:00
|
|
|
* $ref: '#/components/examples/rows'
|
2022-02-18 07:58:09 +13:00
|
|
|
*/
|
2022-02-23 06:38:27 +13:00
|
|
|
router.post(
|
|
|
|
"/tables/:tableId/rows/search",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
|
|
|
controller.search
|
|
|
|
)
|
2022-02-18 07:58:09 +13:00
|
|
|
|
2022-02-18 08:55:37 +13:00
|
|
|
/**
|
|
|
|
* @openapi
|
|
|
|
* /tables/{tableId}/rows:
|
|
|
|
* post:
|
2022-02-19 04:47:15 +13:00
|
|
|
* summary: Creates a new row within a specified table.
|
|
|
|
* tags:
|
|
|
|
* - rows
|
2022-02-18 08:55:37 +13:00
|
|
|
* parameters:
|
|
|
|
* - $ref: '#/components/parameters/tableId'
|
2022-02-19 06:44:08 +13:00
|
|
|
* - $ref: '#/components/parameters/appId'
|
2022-02-19 04:47:15 +13:00
|
|
|
* requestBody:
|
|
|
|
* required: true
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
2022-02-19 06:44:08 +13:00
|
|
|
* $ref: '#/components/schemas/row'
|
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/inputRow'
|
2022-02-18 08:55:37 +13:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: Returns the created row, including the ID which has been generated for it.
|
2022-02-19 04:47:15 +13:00
|
|
|
* This can be found in the Budibase portal, viewed under the developer information.
|
2022-02-18 08:55:37 +13:00
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
2022-02-23 03:10:01 +13:00
|
|
|
* $ref: '#/components/schemas/rowOutput'
|
2022-02-19 04:47:15 +13:00
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/row'
|
2022-02-18 08:55:37 +13:00
|
|
|
*/
|
2022-02-23 06:38:27 +13:00
|
|
|
router.post(
|
|
|
|
"/tables/:tableId/rows",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
|
|
|
controller.create
|
|
|
|
)
|
2022-02-18 07:58:09 +13:00
|
|
|
|
2022-02-19 04:47:15 +13:00
|
|
|
/**
|
|
|
|
* @openapi
|
|
|
|
* /tables/{tableId}/rows/{rowId}:
|
|
|
|
* put:
|
|
|
|
* summary: Update a single row within a specified table.
|
|
|
|
* tags:
|
|
|
|
* - rows
|
|
|
|
* parameters:
|
|
|
|
* - $ref: '#/components/parameters/tableId'
|
|
|
|
* - $ref: '#/components/parameters/rowId'
|
2022-02-19 06:44:08 +13:00
|
|
|
* - $ref: '#/components/parameters/appId'
|
|
|
|
* requestBody:
|
|
|
|
* required: true
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
|
|
|
* $ref: '#/components/schemas/row'
|
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/inputRow'
|
2022-02-19 04:47:15 +13:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: Returns the created row, including the ID which has been generated for it.
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
2022-02-23 03:10:01 +13:00
|
|
|
* $ref: '#/components/schemas/rowOutput'
|
2022-02-19 04:47:15 +13:00
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/row'
|
|
|
|
*/
|
2022-02-23 06:38:27 +13:00
|
|
|
router.put(
|
|
|
|
"/tables/:tableId/rows/:rowId",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
|
|
|
controller.update
|
|
|
|
)
|
2022-02-18 07:58:09 +13:00
|
|
|
|
2022-02-19 04:47:15 +13:00
|
|
|
/**
|
|
|
|
* @openapi
|
|
|
|
* /tables/{tableId}/rows/{rowId}:
|
|
|
|
* delete:
|
|
|
|
* summary: Delete a single row from the specified table.
|
|
|
|
* tags:
|
|
|
|
* - rows
|
|
|
|
* parameters:
|
|
|
|
* - $ref: '#/components/parameters/tableId'
|
|
|
|
* - $ref: '#/components/parameters/rowId'
|
2022-02-19 06:44:08 +13:00
|
|
|
* - $ref: '#/components/parameters/appId'
|
2022-02-19 04:47:15 +13:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: Returns the deleted row, including the ID which has been generated for it.
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
2022-02-23 03:10:01 +13:00
|
|
|
* $ref: '#/components/schemas/rowOutput'
|
2022-02-19 04:47:15 +13:00
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/row'
|
|
|
|
*/
|
2022-02-23 06:38:27 +13:00
|
|
|
router.delete(
|
|
|
|
"/tables/:tableId/rows/:rowId",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
|
|
|
controller.delete
|
|
|
|
)
|
2022-02-18 07:58:09 +13:00
|
|
|
|
2022-02-19 04:47:15 +13:00
|
|
|
/**
|
|
|
|
* @openapi
|
|
|
|
* /tables/{tableId}/rows/{rowId}:
|
|
|
|
* get:
|
|
|
|
* summary: Get a single row from the specified table.
|
|
|
|
* tags:
|
|
|
|
* - rows
|
|
|
|
* parameters:
|
|
|
|
* - $ref: '#/components/parameters/tableId'
|
|
|
|
* - $ref: '#/components/parameters/rowId'
|
2022-02-19 06:44:08 +13:00
|
|
|
* - $ref: '#/components/parameters/appId'
|
2022-02-19 04:47:15 +13:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: Returns the retrieved row.
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
2022-02-23 03:10:01 +13:00
|
|
|
* $ref: '#/components/schemas/rowOutput'
|
2022-02-19 04:47:15 +13:00
|
|
|
* examples:
|
|
|
|
* row:
|
|
|
|
* $ref: '#/components/examples/row'
|
|
|
|
*/
|
2022-02-23 06:38:27 +13:00
|
|
|
router.get(
|
|
|
|
"/tables/:tableId/rows/:rowId",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
|
|
|
controller.read
|
|
|
|
)
|
2022-02-18 07:58:09 +13:00
|
|
|
|
|
|
|
module.exports = router
|