2020-05-07 11:53:34 +02:00
|
|
|
const Router = require("@koa/router")
|
|
|
|
const controller = require("../controllers/screen")
|
2020-05-21 15:31:23 +02:00
|
|
|
const authorized = require("../../middleware/authorized")
|
2020-11-11 18:34:15 +01:00
|
|
|
const { BUILDER } = require("../../utilities/security/permissions")
|
2020-11-04 13:36:38 +01:00
|
|
|
const joiValidator = require("../../middleware/joi-validator")
|
|
|
|
const Joi = require("joi")
|
2020-04-29 21:29:42 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
const router = Router()
|
2020-04-29 21:29:42 +02:00
|
|
|
|
2020-11-04 13:36:38 +01:00
|
|
|
function generateSaveValidation() {
|
|
|
|
// prettier-ignore
|
|
|
|
return joiValidator.body(Joi.object({
|
|
|
|
_css: Joi.string().allow(""),
|
|
|
|
name: Joi.string().required(),
|
2020-11-13 16:35:20 +01:00
|
|
|
routing: Joi.array().items(Joi.object({
|
|
|
|
route: Joi.string().required(),
|
|
|
|
accessLevelId: Joi.string().required(),
|
|
|
|
})).required(),
|
2020-11-04 13:36:38 +01:00
|
|
|
props: Joi.object({
|
2020-11-13 16:35:20 +01:00
|
|
|
_id: Joi.string().required(),
|
|
|
|
_component: Joi.string().required(),
|
|
|
|
_children: Joi.array().required(),
|
|
|
|
_instanceName: Joi.string().required(),
|
|
|
|
_styles: Joi.object().required(),
|
|
|
|
type: Joi.string().optional(),
|
|
|
|
table: Joi.string().optional(),
|
|
|
|
}).required().unknown(true),
|
|
|
|
}).unknown(true))
|
2020-11-04 13:36:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 21:29:42 +02:00
|
|
|
router
|
2020-11-04 13:36:38 +01:00
|
|
|
.get("/api/screens", authorized(BUILDER), controller.fetch)
|
2020-11-04 15:05:11 +01:00
|
|
|
.get("/api/screens/:pageId", authorized(BUILDER), controller.find)
|
2020-11-04 13:36:38 +01:00
|
|
|
.post(
|
2020-11-04 15:05:11 +01:00
|
|
|
"/api/screens/:pageId",
|
2020-11-04 13:36:38 +01:00
|
|
|
authorized(BUILDER),
|
|
|
|
generateSaveValidation(),
|
|
|
|
controller.save
|
|
|
|
)
|
2020-11-04 15:05:11 +01:00
|
|
|
.delete(
|
|
|
|
"/api/screens/:screenId/:revId",
|
|
|
|
authorized(BUILDER),
|
|
|
|
controller.destroy
|
|
|
|
)
|
2020-04-29 21:29:42 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
module.exports = router
|