forked from tsai/budibase
6 changed files with 79 additions and 51 deletions
@ -1,36 +1,58 @@ |
|||||
const CouchDB = require("../../../db") |
const CouchDB = require("../../../db") |
||||
const { |
const { getGroupParams, StaticDatabases } = require("@budibase/auth") |
||||
hash, |
const { generateGroupID } = require("@budibase/auth") |
||||
generateUserID, |
|
||||
getUserParams, |
const GLOBAL_DB = StaticDatabases.GLOBAL.name |
||||
StaticDatabases, |
|
||||
} = require("@budibase/auth") |
exports.save = async function(ctx) { |
||||
const { UserStatus } = require("../../../constants") |
const db = new CouchDB(GLOBAL_DB) |
||||
|
const groupDoc = ctx.request.body |
||||
const USER_DB = StaticDatabases.USER.name |
|
||||
|
// Group does not exist yet
|
||||
exports.save = async function(ctx, next) { |
if (!groupDoc._id) { |
||||
const db = new CouchDB(USER_DB) |
groupDoc._id = generateGroupID() |
||||
const doc = ctx.request.body |
} |
||||
|
|
||||
const groupDoc = { |
try { |
||||
users: ["us:1234", "us:1234"], |
const response = await db.post(groupDoc) |
||||
managers: ["us:1234"], |
ctx.body = { |
||||
defaultRole: "BASIC", |
_id: response.id, |
||||
apps: { |
_rev: response.rev, |
||||
abc123: "ADMIN", |
} |
||||
}, |
} catch (err) { |
||||
|
ctx.throw(err.status, err) |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
exports.fetch = async function(ctx, next) { |
exports.fetch = async function(ctx) { |
||||
const db = new CouchDB(USER_DB) |
const db = new CouchDB(GLOBAL_DB) |
||||
|
const response = await db.allDocs( |
||||
|
getGroupParams(undefined, { |
||||
|
include_docs: true, |
||||
|
}) |
||||
|
) |
||||
|
const groups = response.rows.map(row => row.doc) |
||||
|
ctx.body = groups |
||||
} |
} |
||||
|
|
||||
exports.find = async function(ctx, next) { |
exports.find = async function(ctx) { |
||||
const db = new CouchDB(USER_DB) |
const db = new CouchDB(GLOBAL_DB) |
||||
|
try { |
||||
|
const record = await db.get(ctx.params.id) |
||||
|
ctx.body = record |
||||
|
} catch (err) { |
||||
|
ctx.throw(err.status, err) |
||||
|
} |
||||
} |
} |
||||
|
|
||||
exports.destroy = async function(ctx, next) { |
exports.destroy = async function(ctx) { |
||||
const db = new CouchDB(USER_DB) |
const db = new CouchDB(GLOBAL_DB) |
||||
|
const { id, rev } = ctx.params |
||||
|
|
||||
|
try { |
||||
|
await db.remove(id, rev) |
||||
|
ctx.body = { message: "Group deleted successfully" } |
||||
|
} catch (err) { |
||||
|
ctx.throw(err.status, err) |
||||
|
} |
||||
} |
} |
||||
|
|||||
@ -1,7 +0,0 @@ |
|||||
const groups = require("./groups") |
|
||||
const users = require("./users") |
|
||||
|
|
||||
module.exports = { |
|
||||
groups, |
|
||||
users, |
|
||||
} |
|
||||
Loading…
Reference in new issue