7c16abc8eb
* feat(workspaces): add workspaces module with roles and scopes * feat(workspaces): add domain, graphql and persistent storage dataschema * fix(workspaces): correct db injections * chore(workspaces): add EE license * chore(license): mentions workspaces separately in license file * fix(core): roles import in migration * fix(workspaces): drop workspace_acl on down migration * fix(workspaces): roles constants * fix(workspaces): coding standards --------- Co-authored-by: Dimitrie Stefanescu <didimitrie@gmail.com>
23 lines
630 B
TypeScript
23 lines
630 B
TypeScript
import { GetRoles, UpsertRole } from '@/modules/shared/domain/rolesAndScopes/operations'
|
|
import { UserRole } from '@/modules/shared/domain/rolesAndScopes/types'
|
|
import { Knex } from 'knex'
|
|
|
|
let roles: UserRole[]
|
|
|
|
export const getRolesFactory =
|
|
({ db }: { db: Knex }): GetRoles =>
|
|
async () => {
|
|
if (roles) return roles
|
|
roles = await db('user_roles').select('*')
|
|
return roles
|
|
}
|
|
|
|
export const registerOrUpdateRole =
|
|
({ db }: { db: Knex }): UpsertRole =>
|
|
async ({ role }) => {
|
|
await db('user_roles')
|
|
.insert(role)
|
|
.onConflict('name')
|
|
.merge(['weight', 'description', 'resourceTarget'])
|
|
}
|