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()
|
|
|
|
|
2020-04-06 15:28:22 +02:00
|
|
|
router.post("/_builder/api/:appname/pages/:pageName", async ctx => {
|
|
|
|
await buildPage(
|
|
|
|
ctx.config,
|
|
|
|
ctx.params.appname,
|
|
|
|
ctx.params.pageName,
|
|
|
|
ctx.request.body
|
|
|
|
)
|
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
})
|
|
|
|
|
2020-04-03 17:15:53 +02:00
|
|
|
router.get("/_builder/api/:appname/pages/:pagename/screens", async ctx => {
|
|
|
|
ctx.body = await listScreens(
|
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.response.status = StatusCodes.OK
|
|
|
|
})
|
|
|
|
|
|
|
|
router
|
|
|
|
.post("/_builder/api/:appname/pages/:pagename/screen", async ctx => {
|
|
|
|
ctx.body = await saveScreen(
|
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
|
|
|
|
)
|
|
|
|
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
|