2020-04-09 17:53:48 +02:00
|
|
|
const couchdb = require("../../db");
|
|
|
|
|
|
|
|
const controller = {
|
|
|
|
fetch: async ctx => {
|
2020-04-13 17:22:30 +02:00
|
|
|
const db = couchdb.db.use(ctx.params.instanceId);
|
|
|
|
const designDoc = await db.get("_design/database");
|
|
|
|
ctx.body = designDoc.views;
|
2020-04-09 17:53:48 +02:00
|
|
|
},
|
|
|
|
create: async ctx => {
|
2020-04-13 17:22:30 +02:00
|
|
|
const db = couchdb.db.use(ctx.params.instanceId);
|
|
|
|
const { name, ...viewDefinition } = ctx.request.body;
|
|
|
|
|
|
|
|
const designDoc = await db.get("_design/database");
|
|
|
|
designDoc.views = {
|
|
|
|
...designDoc.views,
|
|
|
|
[name]: viewDefinition
|
|
|
|
};
|
|
|
|
const newView = await db.insert(designDoc, designDoc._id);
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
...newView,
|
|
|
|
message: `View ${name} created successfully.`,
|
|
|
|
status: 200,
|
|
|
|
}
|
2020-04-09 17:53:48 +02:00
|
|
|
},
|
|
|
|
destroy: async ctx => {
|
2020-04-20 17:17:11 +02:00
|
|
|
const db = couchdb.db.use(ctx.params.instanceId);
|
2020-04-09 17:53:48 +02:00
|
|
|
ctx.body = await database.destroy(ctx.params.userId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = controller;
|