1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00
budibase/packages/server/src/api/controllers/screen.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-02 04:32:54 +13:00
const CouchDB = require("../../db")
2020-11-04 05:27:28 +13:00
const { getScreenParams, generateScreenID } = require("../../db/utils")
const { AccessController } = require("@budibase/auth/roles")
2021-05-04 22:32:22 +12:00
exports.fetch = async ctx => {
const appId = ctx.appId
const db = new CouchDB(appId)
2020-11-04 05:27:28 +13:00
const screens = (
await db.allDocs(
getScreenParams(null, {
include_docs: true,
})
)
2021-05-04 22:32:22 +12:00
).rows.map(element => element.doc)
ctx.body = await new AccessController(appId).checkScreensAccess(
screens,
ctx.user.role._id
2020-11-04 05:27:28 +13:00
)
}
2021-05-04 22:32:22 +12:00
exports.save = async ctx => {
const appId = ctx.appId
2020-11-04 05:27:28 +13:00
const db = new CouchDB(appId)
let screen = ctx.request.body
2020-11-04 05:27:28 +13:00
if (!screen._id) {
2020-11-21 06:47:13 +13:00
screen._id = generateScreenID()
2020-11-04 05:27:28 +13: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 22:32:22 +12:00
exports.destroy = async ctx => {
const db = new CouchDB(ctx.appId)
await db.remove(ctx.params.screenId, ctx.params.screenRev)
ctx.body = {
message: "Screen deleted successfully",
}
ctx.status = 200
}