2020-05-07 21:53:34 +12:00
|
|
|
const Router = require("@koa/router")
|
2020-04-07 01:05:57 +12:00
|
|
|
const StatusCodes = require("../../utilities/statusCodes")
|
2020-04-04 04:15:53 +13:00
|
|
|
const {
|
|
|
|
listScreens,
|
|
|
|
saveScreen,
|
2020-04-07 01:28:22 +12:00
|
|
|
buildPage,
|
|
|
|
renameScreen,
|
2020-05-07 21:53:34 +12:00
|
|
|
deleteScreen,
|
2020-04-04 04:15:53 +13:00
|
|
|
} = require("../../utilities/builder")
|
2020-05-22 01:31:23 +12:00
|
|
|
const authorized = require("../../middleware/authorized")
|
|
|
|
const { BUILDER } = require("../../utilities/accessLevels")
|
2020-04-04 04:15:53 +13:00
|
|
|
|
|
|
|
const router = Router()
|
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
router.post(
|
|
|
|
"/_builder/api/:appId/pages/:pageName",
|
|
|
|
authorized(BUILDER),
|
|
|
|
async ctx => {
|
|
|
|
await buildPage(
|
|
|
|
ctx.config,
|
|
|
|
ctx.params.appId,
|
|
|
|
ctx.params.pageName,
|
|
|
|
ctx.request.body
|
|
|
|
)
|
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
}
|
|
|
|
)
|
2020-04-07 01:28:22 +12:00
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
router.get(
|
|
|
|
"/_builder/api/:appId/pages/:pagename/screens",
|
|
|
|
authorized(BUILDER),
|
|
|
|
async ctx => {
|
|
|
|
ctx.body = await listScreens(
|
|
|
|
ctx.config,
|
|
|
|
ctx.params.appId,
|
|
|
|
ctx.params.pagename
|
|
|
|
)
|
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
}
|
|
|
|
)
|
2020-04-04 04:15:53 +13:00
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
router.post(
|
|
|
|
"/_builder/api/:appId/pages/:pagename/screen",
|
|
|
|
authorized(BUILDER),
|
|
|
|
async ctx => {
|
|
|
|
ctx.body = await saveScreen(
|
|
|
|
ctx.config,
|
|
|
|
ctx.params.appId,
|
|
|
|
ctx.params.pagename,
|
|
|
|
ctx.request.body
|
|
|
|
)
|
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
}
|
|
|
|
)
|
2020-04-04 04:15:53 +13:00
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
router.patch(
|
|
|
|
"/_builder/api/:appname/pages/:pagename/screen",
|
|
|
|
authorized(BUILDER),
|
|
|
|
async ctx => {
|
|
|
|
await renameScreen(
|
|
|
|
ctx.config,
|
|
|
|
ctx.params.appname,
|
|
|
|
ctx.params.pagename,
|
|
|
|
ctx.request.body.oldname,
|
|
|
|
ctx.request.body.newname
|
|
|
|
)
|
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
}
|
|
|
|
)
|
2020-04-04 04:15:53 +13:00
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
router.delete(
|
2020-07-22 02:01:32 +12:00
|
|
|
"/_builder/api/pages/:pagename/screens/:id",
|
2020-05-22 01:31:23 +12:00
|
|
|
authorized(BUILDER),
|
|
|
|
async ctx => {
|
|
|
|
await deleteScreen(
|
|
|
|
ctx.config,
|
2020-07-22 02:01:32 +12:00
|
|
|
ctx.user.appId,
|
2020-05-22 01:31:23 +12:00
|
|
|
ctx.params.pagename,
|
2020-07-22 02:01:32 +12:00
|
|
|
ctx.params.id
|
2020-05-22 01:31:23 +12:00
|
|
|
)
|
2020-04-04 04:15:53 +13:00
|
|
|
|
2020-05-22 01:31:23 +12:00
|
|
|
ctx.response.status = StatusCodes.OK
|
|
|
|
}
|
|
|
|
)
|
2020-04-04 04:15:53 +13:00
|
|
|
|
2020-05-07 21:53:34 +12:00
|
|
|
module.exports = router
|