Files
speckle-server/packages/server/modules/workspaces/index.ts
T
Chuck Driesler b5c9e62bcb chore(workspaces): perform workspace project role update via events (#2980)
* chore(workspaces): perform workspace project role update via events

* chore(workspaces): commented

* fix(workspaces): transactions in events

* fix(workspaces): transaction limits
2024-09-13 10:30:06 +02:00

51 lines
1.8 KiB
TypeScript

import { moduleLogger } from '@/logging/logging'
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
import { registerOrUpdateScopeFactory } from '@/modules/shared/repositories/scopes'
import db from '@/db/knex'
import { Optional, SpeckleModule } from '@/modules/shared/helpers/typeHelper'
import { workspaceRoles } from '@/modules/workspaces/roles'
import { workspaceScopes } from '@/modules/workspaces/scopes'
import { registerOrUpdateRole } from '@/modules/shared/repositories/roles'
import { initializeEventListenersFactory } from '@/modules/workspaces/events/eventListener'
import { validateModuleLicense } from '@/modules/gatekeeper/services/validateLicense'
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
let quitListeners: Optional<() => void> = undefined
const initScopes = async () => {
const registerFunc = registerOrUpdateScopeFactory({ db })
await Promise.all(workspaceScopes.map((scope) => registerFunc({ scope })))
}
const initRoles = async () => {
const registerFunc = registerOrUpdateRole({ db })
await Promise.all(workspaceRoles.map((role) => registerFunc({ role })))
}
const workspacesModule: SpeckleModule = {
async init(_, isInitial) {
if (!FF_WORKSPACES_MODULE_ENABLED) return
const isWorkspaceLicenseValid = await validateModuleLicense({
requiredModules: ['workspaces']
})
if (!isWorkspaceLicenseValid)
throw new Error(
'The workspaces module needs a valid license to run, contact Speckle to get one.'
)
moduleLogger.info('⚒️ Init workspaces module')
if (isInitial) {
quitListeners = initializeEventListenersFactory({ db })()
}
await Promise.all([initScopes(), initRoles()])
},
shutdown() {
if (!FF_WORKSPACES_MODULE_ENABLED) return
quitListeners?.()
}
}
export = workspacesModule