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.
 
 
 
 
 
 

66 lines
1.5 KiB

const {
generateUserGroupID,
getUserGroupsParams,
} = require("@budibase/backend-core/db")
const { Configs } = require("../../../constants")
const email = require("../../../utilities/email")
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
const env = require("../../../environment")
const {
withCache,
CacheKeys,
bustCache,
} = require("@budibase/backend-core/cache")
exports.save = async function (ctx: any) {
const db = getGlobalDB()
// Config does not exist yet
if (!ctx.request.body._id) {
ctx.request.body._id = generateUserGroupID(ctx.request.body.name)
}
try {
const response = await db.put(ctx.request.body)
ctx.body = {
_id: response.id,
_rev: response.rev,
}
} catch (err) {
ctx.throw(400, err)
}
}
exports.fetch = async function (ctx: any) {
const db = getGlobalDB()
const response = await db.allDocs(
getUserGroupsParams(null, {
include_docs: true,
})
)
ctx.body = response.rows.map((row: any) => row.doc)
}
exports.destroy = async function (ctx: any) {
const db = getGlobalDB()
const { id, rev } = ctx.params
try {
await db.remove(id, rev)
ctx.body = { message: "Group deleted successfully" }
} catch (err: any) {
ctx.throw(err.status, err)
}
}
/**
* Gets a group by ID from the global database.
*/
exports.find = async function (ctx: any) {
const db = getGlobalDB()
try {
ctx.body = await db.get(ctx.params.id)
} catch (err: any) {
ctx.throw(err.status, err)
}
}