1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00
budibase/packages/server/src/api/controllers/view.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-05-07 21:53:34 +12:00
const CouchDB = require("../../db")
2020-04-10 03:53:48 +12:00
const controller = {
2020-05-18 22:18:31 +12:00
query: async () => {},
2020-04-10 03:53:48 +12:00
fetch: async ctx => {
2020-06-19 03:59:31 +12:00
const db = new CouchDB(ctx.user.instanceId)
2020-05-07 21:53:34 +12:00
const designDoc = await db.get("_design/database")
const response = []
for (let name in designDoc.views) {
2020-05-07 21:53:34 +12:00
if (
!name.startsWith("all") &&
name !== "by_type" &&
2020-06-02 08:31:55 +12:00
name !== "by_username" &&
2020-06-02 08:26:32 +12:00
name !== "by_workflow_trigger"
2020-05-07 21:53:34 +12:00
) {
response.push({
name,
2020-05-07 21:53:34 +12:00
...designDoc.views[name],
})
}
}
ctx.body = response
2020-04-10 03:53:48 +12:00
},
create: async ctx => {
2020-06-19 03:59:31 +12:00
const db = new CouchDB(ctx.user.instanceId)
2020-05-15 02:12:30 +12:00
const newView = ctx.request.body
2020-04-14 03:22:30 +12:00
2020-05-07 21:53:34 +12:00
const designDoc = await db.get("_design/database")
2020-04-14 03:22:30 +12:00
designDoc.views = {
...designDoc.views,
2020-05-15 02:12:30 +12:00
[newView.name]: newView,
2020-05-07 21:53:34 +12:00
}
2020-05-15 02:12:30 +12:00
await db.put(designDoc)
2020-04-14 03:22:30 +12:00
2020-05-15 02:12:30 +12:00
ctx.body = newView
ctx.message = `View ${newView.name} created successfully.`
2020-04-10 03:53:48 +12:00
},
destroy: async ctx => {
2020-06-19 03:59:31 +12:00
const db = new CouchDB(ctx.user.instanceId)
ctx.body = await db.destroy(ctx.params.userId)
2020-05-07 21:53:34 +12:00
},
2020-04-10 03:53:48 +12:00
}
2020-05-07 21:53:34 +12:00
module.exports = controller