2020-04-07 18:25:09 +02:00
|
|
|
const couchdb = require("../../db");
|
|
|
|
|
|
|
|
const controller = {
|
|
|
|
fetch: async ctx => {
|
|
|
|
const database = couchdb.db.use(ctx.params.databaseId);
|
2020-04-08 17:57:27 +02:00
|
|
|
const data = await database.view("database", "by_type", {
|
2020-04-08 12:18:30 +02:00
|
|
|
include_docs: true,
|
|
|
|
key: ["user"]
|
2020-04-08 17:57:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ctx.body = data.rows
|
2020-04-07 18:25:09 +02:00
|
|
|
},
|
|
|
|
create: async ctx => {
|
|
|
|
const database = couchdb.db.use(ctx.params.databaseId);
|
2020-04-07 18:38:01 +02:00
|
|
|
ctx.body = await database.insert(ctx.request.body);
|
2020-04-07 18:25:09 +02:00
|
|
|
},
|
|
|
|
destroy: async ctx => {
|
|
|
|
const database = couchdb.db.use(ctx.params.databaseId);
|
|
|
|
ctx.body = await database.destroy(ctx.params.userId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = controller;
|