2022-09-23 01:09:20 +12:00
|
|
|
import Router from "@koa/router"
|
2022-09-23 01:59:28 +12:00
|
|
|
import * as controller from "../../controllers/global/templates"
|
2022-09-23 01:09:20 +12:00
|
|
|
import { TemplatePurpose, TemplateTypes } from "../../../constants"
|
|
|
|
import { auth as authCore } from "@budibase/backend-core"
|
|
|
|
import Joi from "joi"
|
|
|
|
const { adminOnly, joiValidator } = authCore
|
2021-04-22 03:42:44 +12:00
|
|
|
|
2022-09-23 01:59:28 +12:00
|
|
|
const router = new Router()
|
2021-04-22 03:42:44 +12:00
|
|
|
|
2021-04-22 05:15:57 +12:00
|
|
|
function buildTemplateSaveValidation() {
|
|
|
|
// prettier-ignore
|
|
|
|
return joiValidator.body(Joi.object({
|
|
|
|
_id: Joi.string().allow(null, ""),
|
|
|
|
_rev: Joi.string().allow(null, ""),
|
|
|
|
ownerId: Joi.string().allow(null, ""),
|
|
|
|
name: Joi.string().allow(null, ""),
|
|
|
|
contents: Joi.string().required(),
|
|
|
|
purpose: Joi.string().required().valid(...Object.values(TemplatePurpose)),
|
|
|
|
type: Joi.string().required().valid(...Object.values(TemplateTypes)),
|
|
|
|
}).required().unknown(true).optional())
|
|
|
|
}
|
2021-04-22 03:42:44 +12:00
|
|
|
|
|
|
|
router
|
2021-08-05 20:59:08 +12:00
|
|
|
.get("/api/global/template/definitions", controller.definitions)
|
2021-05-20 02:09:57 +12:00
|
|
|
.post(
|
2021-08-05 20:59:08 +12:00
|
|
|
"/api/global/template",
|
2021-05-20 02:09:57 +12:00
|
|
|
adminOnly,
|
|
|
|
buildTemplateSaveValidation(),
|
|
|
|
controller.save
|
|
|
|
)
|
2021-08-05 20:59:08 +12:00
|
|
|
.get("/api/global/template", controller.fetch)
|
|
|
|
.get("/api/global/template/:type", controller.fetchByType)
|
|
|
|
.get("/api/global/template/:ownerId", controller.fetchByOwner)
|
|
|
|
.get("/api/global/template/:id", controller.find)
|
|
|
|
.delete("/api/global/template/:id/:rev", adminOnly, controller.destroy)
|
2021-04-24 05:07:39 +12:00
|
|
|
|
2022-09-23 01:59:28 +12:00
|
|
|
export default router
|