Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.1 KiB

const CouchDB = require("../../db");
const bcrypt = require("../../utilities/bcrypt");
exports.fetch = async function(ctx) {
const database = new CouchDB(ctx.config)(ctx.params.instanceId);
const data = await database.query("database/by_type", {
include_docs: true,
key: ["user"]
});
ctx.body = data.rows.map(row => row.doc);
};
exports.create = async function(ctx) {
const database = new CouchDB(ctx.config)(ctx.params.instanceId);
const { username, password, name } = ctx.request.body;
if (!username || !password) ctx.throw(400, "Username and Password Required.");
const response = await database.post({
username,
password: await bcrypt.hash(password),
name,
type: "user"
});
ctx.body = {
user: {
id: response.id,
rev: response.rev,
username,
name
},
message: `User created successfully.`,
status: 200
}
};
exports.destroy = async function(ctx) {
const database = new CouchDB(ctx.config)(ctx.params.instanceId);
const response = await database.destroy(ctx.params.userId)
ctx.body = {
...response,
message: `User deleted.`,
status: 200
}
};