Adding an API for publishing an event from the frontend.

This commit is contained in:
mike12345567 2023-01-23 18:56:44 +00:00
parent 5a2937c8d2
commit 557a9a8eeb
5 changed files with 33 additions and 0 deletions

View File

View File

@ -0,0 +1,7 @@
export enum EventPublishType {
ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED = "environment_variable_upgrade_panel_opened",
}
export interface PostEventPublishRequest {
type: EventPublishType
}

View File

@ -1 +1,2 @@
export * from "./environmentVariables" export * from "./environmentVariables"
export * from "./events"

View File

@ -0,0 +1,17 @@
import {
UserCtx,
PostEventPublishRequest,
EventPublishType,
} from "@budibase/types"
import { events } from "@budibase/backend-core"
export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
switch (ctx.request.body.type) {
case EventPublishType.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED:
await events.environmentVariable.upgradePanelOpened(ctx.user._id!)
break
default:
ctx.throw(400, "Invalid publish event type.")
}
ctx.status = 200
}

View File

@ -0,0 +1,8 @@
import Router from "@koa/router"
import * as controller from "../../controllers/global/events"
const router: Router = new Router()
router.post("/api/global/event/publish", controller.publish)
export default router