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-05-07 21:53:34 +12:00
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
|
|
|
const designDoc = await db.get("_design/database")
|
|
|
|
const response = []
|
2020-04-29 01:39:35 +12:00
|
|
|
|
|
|
|
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
|
|
|
) {
|
2020-04-29 01:39:35 +12:00
|
|
|
response.push({
|
|
|
|
name,
|
2020-05-07 21:53:34 +12:00
|
|
|
...designDoc.views[name],
|
2020-04-29 01:39:35 +12:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = response
|
2020-04-10 03:53:48 +12:00
|
|
|
},
|
|
|
|
create: async ctx => {
|
2020-05-07 21:53:34 +12:00
|
|
|
const db = new CouchDB(ctx.params.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-05-07 21:53:34 +12:00
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
2020-04-24 01:37:08 +12:00
|
|
|
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
|