2022-11-22 19:49:19 +01:00
|
|
|
import Router from "@koa/router"
|
|
|
|
import * as queryController from "../controllers/query"
|
|
|
|
import authorized from "../../middleware/authorized"
|
|
|
|
import { permissions } from "@budibase/backend-core"
|
|
|
|
import {
|
2021-02-08 18:22:07 +01:00
|
|
|
bodyResource,
|
|
|
|
bodySubResource,
|
|
|
|
paramResource,
|
2022-11-22 19:49:19 +01:00
|
|
|
} from "../../middleware/resourceId"
|
|
|
|
import {
|
2024-02-21 22:30:22 +01:00
|
|
|
generateQueryValidation,
|
2024-02-22 18:06:08 +01:00
|
|
|
generateQueryPreviewValidation,
|
2022-11-22 19:49:19 +01:00
|
|
|
} from "../controllers/query/validation"
|
2023-11-20 21:52:29 +01:00
|
|
|
|
2022-11-22 19:49:19 +01:00
|
|
|
const { BUILDER, PermissionType, PermissionLevel } = permissions
|
2020-12-18 19:19:43 +01:00
|
|
|
|
2022-11-22 19:49:19 +01:00
|
|
|
const router: Router = new Router()
|
2020-12-18 19:19:43 +01:00
|
|
|
|
2021-01-06 13:28:51 +01:00
|
|
|
router
|
|
|
|
.get("/api/queries", authorized(BUILDER), queryController.fetch)
|
2021-01-11 22:01:21 +01:00
|
|
|
.post(
|
|
|
|
"/api/queries",
|
2021-02-08 18:22:07 +01:00
|
|
|
bodySubResource("datasourceId", "_id"),
|
2021-01-11 22:01:21 +01:00
|
|
|
authorized(BUILDER),
|
|
|
|
generateQueryValidation(),
|
|
|
|
queryController.save
|
|
|
|
)
|
2021-11-29 11:37:31 +01:00
|
|
|
.post("/api/queries/import", authorized(BUILDER), queryController.import)
|
2021-01-11 22:01:21 +01:00
|
|
|
.post(
|
|
|
|
"/api/queries/preview",
|
2021-02-08 18:22:07 +01:00
|
|
|
bodyResource("datasourceId"),
|
2021-01-11 22:01:21 +01:00
|
|
|
authorized(BUILDER),
|
|
|
|
generateQueryPreviewValidation(),
|
|
|
|
queryController.preview
|
|
|
|
)
|
2021-02-05 17:45:23 +01:00
|
|
|
.get(
|
|
|
|
"/api/queries/:queryId",
|
2021-11-09 17:25:23 +01:00
|
|
|
paramResource("queryId"),
|
2022-11-17 15:59:18 +01:00
|
|
|
authorized(PermissionType.QUERY, PermissionLevel.READ),
|
2021-02-05 17:45:23 +01:00
|
|
|
queryController.find
|
|
|
|
)
|
2021-12-16 12:41:28 +01:00
|
|
|
// DEPRECATED - use new query endpoint for future work
|
2021-01-11 22:01:21 +01:00
|
|
|
.post(
|
|
|
|
"/api/queries/:queryId",
|
2021-02-08 18:22:07 +01:00
|
|
|
paramResource("queryId"),
|
2022-11-17 15:59:18 +01:00
|
|
|
authorized(PermissionType.QUERY, PermissionLevel.WRITE),
|
2021-12-16 12:41:28 +01:00
|
|
|
queryController.executeV1
|
|
|
|
)
|
2021-01-12 18:45:43 +01:00
|
|
|
.delete(
|
|
|
|
"/api/queries/:queryId/:revId",
|
2021-02-08 18:22:07 +01:00
|
|
|
paramResource("queryId"),
|
2021-01-12 18:45:43 +01:00
|
|
|
authorized(BUILDER),
|
|
|
|
queryController.destroy
|
|
|
|
)
|
2022-11-22 19:49:19 +01:00
|
|
|
.post(
|
|
|
|
"/api/v2/queries/:queryId",
|
|
|
|
paramResource("queryId"),
|
|
|
|
authorized(PermissionType.QUERY, PermissionLevel.WRITE),
|
|
|
|
queryController.executeV2 as any
|
|
|
|
)
|
2020-12-18 19:19:43 +01:00
|
|
|
|
2023-01-11 10:37:37 +01:00
|
|
|
export default router
|