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

53 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* This controller is not currently fully implemented. Screens are
* currently managed as part of the pages API, please look in api/routes/page.js
* for routes and controllers.
*/
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")
exports.fetch = async ctx => {
2020-11-04 05:27:28 +13:00
const db = new CouchDB(ctx.user.appId)
const screens = await db.allDocs(
getScreenParams(null, {
2020-11-04 05:27:28 +13:00
include_docs: true,
})
)
ctx.body = screens.rows.map(element => element.doc)
}
exports.find = async ctx => {
2020-11-02 04:32:54 +13:00
const db = new CouchDB(ctx.user.appId)
const screens = await db.allDocs(
getScreenParams(ctx.params.pageId, {
include_docs: true,
})
)
ctx.body = screens.response.rows
2020-11-02 04:32:54 +13:00
}
exports.save = async ctx => {
2020-11-04 05:27:28 +13:00
const appId = ctx.user.appId
const db = new CouchDB(appId)
const screen = ctx.request.body
if (!screen._id) {
screen._id = generateScreenID(ctx.params.pageId)
2020-11-04 05:27:28 +13:00
}
delete screen._css
2020-11-04 05:27:28 +13:00
const response = await db.put(screen)
ctx.message = `Screen ${screen.name} saved.`
ctx.body = response
}
exports.destroy = async ctx => {
2020-11-04 05:27:28 +13:00
const db = new CouchDB(ctx.user.appId)
await db.remove(ctx.params.screenId, ctx.params.revId)
ctx.message = "Screen deleted successfully"
}