budibase/packages/server/src/api/controllers/screen.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-11-03 17:27:28 +01:00
const { getScreenParams, generateScreenID } = require("../../db/utils")
const { AccessController } = require("@budibase/backend-core/roles")
const { getAppDB } = require("@budibase/backend-core/context")
2021-05-04 12:32:22 +02:00
exports.fetch = async ctx => {
const db = getAppDB()
2020-11-03 17:27:28 +01:00
const screens = (
await db.allDocs(
getScreenParams(null, {
include_docs: true,
})
)
2021-05-04 12:32:22 +02:00
).rows.map(element => element.doc)
ctx.body = await new AccessController().checkScreensAccess(
screens,
ctx.user.role._id
2020-11-03 17:27:28 +01:00
)
}
2021-05-04 12:32:22 +02:00
exports.save = async ctx => {
const db = getAppDB()
let screen = ctx.request.body
2020-11-03 17:27:28 +01:00
if (!screen._id) {
2020-11-20 18:47:13 +01:00
screen._id = generateScreenID()
2020-11-03 17:27:28 +01:00
}
const response = await db.put(screen)
ctx.message = `Screen ${screen.name} saved.`
ctx.body = {
...screen,
_id: response.id,
_rev: response.rev,
}
}
2021-05-04 12:32:22 +02:00
exports.destroy = async ctx => {
const db = getAppDB()
await db.remove(ctx.params.screenId, ctx.params.screenRev)
ctx.body = {
message: "Screen deleted successfully",
}
ctx.status = 200
}