2020-05-20 18:02:46 +02:00
|
|
|
const Router = require("@koa/router")
|
2020-09-21 14:49:34 +02:00
|
|
|
const controller = require("../controllers/automation")
|
2020-05-27 18:23:01 +02:00
|
|
|
const authorized = require("../../middleware/authorized")
|
2020-11-11 18:34:15 +01:00
|
|
|
const {
|
|
|
|
BUILDER,
|
|
|
|
PermissionLevels,
|
|
|
|
PermissionTypes,
|
2022-01-10 20:33:00 +01:00
|
|
|
} = require("@budibase/backend-core/permissions")
|
2021-02-08 18:22:07 +01:00
|
|
|
const { bodyResource, paramResource } = require("../../middleware/resourceId")
|
2021-09-08 20:29:28 +02:00
|
|
|
const {
|
|
|
|
middleware: appInfoMiddleware,
|
|
|
|
AppType,
|
|
|
|
} = require("../../middleware/appInfo")
|
2022-02-24 12:39:38 +01:00
|
|
|
const { automationValidator } = require("./utils/validators")
|
2020-05-20 18:02:46 +02:00
|
|
|
|
|
|
|
const router = Router()
|
|
|
|
|
|
|
|
router
|
2020-09-14 15:35:03 +02:00
|
|
|
.get(
|
2020-09-21 14:49:34 +02:00
|
|
|
"/api/automations/trigger/list",
|
2020-09-14 15:35:03 +02:00
|
|
|
authorized(BUILDER),
|
|
|
|
controller.getTriggerList
|
|
|
|
)
|
|
|
|
.get(
|
2020-09-21 14:49:34 +02:00
|
|
|
"/api/automations/action/list",
|
2020-09-14 15:35:03 +02:00
|
|
|
authorized(BUILDER),
|
|
|
|
controller.getActionList
|
|
|
|
)
|
2020-09-14 16:34:09 +02:00
|
|
|
.get(
|
2020-09-21 14:49:34 +02:00
|
|
|
"/api/automations/definitions/list",
|
2020-09-14 16:34:09 +02:00
|
|
|
authorized(BUILDER),
|
|
|
|
controller.getDefinitionList
|
|
|
|
)
|
2020-09-21 14:49:34 +02:00
|
|
|
.get("/api/automations", authorized(BUILDER), controller.fetch)
|
2021-02-08 18:22:07 +01:00
|
|
|
.get(
|
|
|
|
"/api/automations/:id",
|
|
|
|
paramResource("id"),
|
|
|
|
authorized(BUILDER),
|
|
|
|
controller.find
|
|
|
|
)
|
2020-09-14 15:35:03 +02:00
|
|
|
.put(
|
2020-09-21 14:49:34 +02:00
|
|
|
"/api/automations",
|
2021-02-08 18:22:07 +01:00
|
|
|
bodyResource("_id"),
|
2020-09-14 15:35:03 +02:00
|
|
|
authorized(BUILDER),
|
2022-02-24 12:39:38 +01:00
|
|
|
automationValidator(true),
|
2020-09-14 15:35:03 +02:00
|
|
|
controller.update
|
|
|
|
)
|
|
|
|
.post(
|
2020-09-21 14:49:34 +02:00
|
|
|
"/api/automations",
|
2020-09-14 15:35:03 +02:00
|
|
|
authorized(BUILDER),
|
2022-02-24 12:39:38 +01:00
|
|
|
automationValidator(false),
|
2020-09-14 15:35:03 +02:00
|
|
|
controller.create
|
|
|
|
)
|
2021-09-08 20:29:28 +02:00
|
|
|
.delete(
|
|
|
|
"/api/automations/:id/:rev",
|
|
|
|
paramResource("id"),
|
|
|
|
authorized(BUILDER),
|
|
|
|
controller.destroy
|
|
|
|
)
|
2022-06-01 17:01:06 +02:00
|
|
|
.post(
|
|
|
|
"/api/automations/logs/search",
|
|
|
|
authorized(BUILDER),
|
|
|
|
controller.logSearch
|
|
|
|
)
|
2020-10-22 18:48:32 +02:00
|
|
|
.post(
|
|
|
|
"/api/automations/:id/trigger",
|
2021-09-08 20:29:28 +02:00
|
|
|
appInfoMiddleware({ appType: AppType.PROD }),
|
2021-02-08 18:22:07 +01:00
|
|
|
paramResource("id"),
|
2020-11-11 18:34:15 +01:00
|
|
|
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
2021-09-08 15:08:22 +02:00
|
|
|
controller.trigger
|
|
|
|
)
|
|
|
|
.post(
|
|
|
|
"/api/automations/:id/test",
|
2021-09-08 20:29:28 +02:00
|
|
|
appInfoMiddleware({ appType: AppType.DEV }),
|
2021-09-08 15:08:22 +02:00
|
|
|
paramResource("id"),
|
|
|
|
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
2021-09-07 20:06:20 +02:00
|
|
|
controller.test
|
2020-10-22 18:48:32 +02:00
|
|
|
)
|
2020-05-20 18:02:46 +02:00
|
|
|
|
|
|
|
module.exports = router
|