budibase/packages/server/middleware/controllers/user.js

31 lines
772 B
JavaScript
Raw Normal View History

2020-04-07 18:25:09 +02:00
const couchdb = require("../../db");
2020-04-09 17:53:48 +02:00
exports.fetch = async function(ctx) {
const database = couchdb.db.use(ctx.params.databaseId);
const data = await database.view("database", "by_type", {
include_docs: true,
key: ["user"]
});
2020-04-08 17:57:27 +02:00
2020-04-09 17:53:48 +02:00
ctx.body = data.rows
};
2020-04-07 18:25:09 +02:00
2020-04-09 17:53:48 +02:00
exports.create = async function(ctx) {
const database = couchdb.db.use(ctx.params.databaseId);
2020-04-10 17:37:59 +02:00
const response = await database.insert(ctx.request.body);
ctx.body = {
...response,
message: `User created successfully.`,
status: 200
}
2020-04-09 17:53:48 +02:00
};
exports.destroy = async function(ctx) {
const database = couchdb.db.use(ctx.params.databaseId);
2020-04-10 17:37:59 +02:00
const response = await database.destroy(ctx.params.userId)
ctx.body = {
...response,
message: `User deleted.`,
status: 200
}
2020-04-09 17:53:48 +02:00
};