budibase/packages/server/api/routes/pages.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-04-03 17:15:53 +02:00
const Router = require("@koa/router");
2020-04-06 15:05:57 +02:00
const StatusCodes = require("../../utilities/statusCodes")
2020-04-03 17:15:53 +02:00
const {
listScreens,
saveScreen,
2020-04-06 15:28:22 +02:00
buildPage,
renameScreen,
deleteScreen
2020-04-03 17:15:53 +02:00
} = require("../../utilities/builder")
const router = Router()
router.post("/_builder/api/:appId/pages/:pageName", async ctx => {
2020-04-06 15:28:22 +02:00
await buildPage(
ctx.config,
ctx.params.appId,
2020-04-06 15:28:22 +02:00
ctx.params.pageName,
ctx.request.body
)
ctx.response.status = StatusCodes.OK
})
router.get("/_builder/api/:appId/pages/:pagename/screens", async ctx => {
2020-04-03 17:15:53 +02:00
ctx.body = await listScreens(
2020-04-06 15:05:57 +02:00
ctx.config,
ctx.params.appId,
2020-04-03 17:15:53 +02:00
ctx.params.pagename
)
ctx.response.status = StatusCodes.OK
})
router
.post("/_builder/api/:appId/pages/:pagename/screen", async ctx => {
2020-04-03 17:15:53 +02:00
ctx.body = await saveScreen(
2020-04-06 15:05:57 +02:00
ctx.config,
ctx.params.appId,
2020-04-03 17:15:53 +02:00
ctx.params.pagename,
ctx.request.body
)
ctx.response.status = StatusCodes.OK
})
router
.patch("/_builder/api/:appname/pages/:pagename/screen", async ctx => {
await renameScreen(
2020-04-06 15:05:57 +02:00
ctx.config,
2020-04-03 17:15:53 +02:00
ctx.params.appname,
ctx.params.pagename,
ctx.request.body.oldname,
ctx.request.body.newname
)
ctx.response.status = StatusCodes.OK
})
router
.delete("/_builder/api/:appname/pages/:pagename/screen/*", async ctx => {
const name = ctx.request.path.replace(
`/_builder/api/${ctx.params.appname}/pages/${ctx.params.pagename}/screen/`,
""
)
await deleteScreen(
2020-04-06 15:05:57 +02:00
ctx.config,
2020-04-03 17:15:53 +02:00
ctx.params.appname,
ctx.params.pagename,
decodeURI(name)
)
ctx.response.status = StatusCodes.OK
})
module.exports = router