6cea72e4f8
* WIP can create project * WIP can create project more work * complete body, stencil tests * feat(shared): move workspace plan types into shared * test progress wip * feat(shared): add more logic to canCreateWorkspaceProject * a few more tests, as a treat * chore(authz): round out tests * fixed loaders, new GQL checks, dataLoaders in auth loaders * fix(authz): get workspace limits loader * chore(authz): update loaders * frontend fixed up to snuff * fix(authz): fix workspace plans for tests * fix(authz): classic * feat(workspaces): emit plan usage from BE * fix(authz): 0 counts * fix(workspaces): fix counts for 0 * chore(workspaces): gqlgen * fix(workspaces): update fragment to use new fields * fix(workspaces): count regional projects correctly --------- Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com> Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
|
|
import { defineRequestDataloaders } from '@/modules/shared/helpers/graphqlHelper'
|
|
import {
|
|
getWorkspaceDomainsFactory,
|
|
getWorkspacesFactory,
|
|
getWorkspacesProjectsCountsFactory
|
|
} from '@/modules/workspaces/repositories/workspaces'
|
|
import {
|
|
WorkspaceDomain,
|
|
WorkspaceWithOptionalRole
|
|
} from '@/modules/workspacesCore/domain/types'
|
|
import { keyBy } from 'lodash'
|
|
|
|
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
|
|
|
|
declare module '@/modules/core/loaders' {
|
|
interface ModularizedDataLoaders
|
|
extends Partial<ReturnType<typeof dataLoadersDefinition>> {}
|
|
}
|
|
|
|
const dataLoadersDefinition = defineRequestDataloaders(
|
|
({ ctx, createLoader, deps: { db } }) => {
|
|
const getWorkspaces = getWorkspacesFactory({ db })
|
|
const getWorkspaceDomains = getWorkspaceDomainsFactory({ db })
|
|
const getWorkspacesProjectsCounts = getWorkspacesProjectsCountsFactory({ db })
|
|
|
|
return {
|
|
workspaces: {
|
|
/**
|
|
* Get workspace, with the active user's role attached
|
|
*/
|
|
getWorkspace: createLoader<string, WorkspaceWithOptionalRole | null>(
|
|
async (ids) => {
|
|
const results = keyBy(
|
|
await getWorkspaces({ workspaceIds: ids.slice(), userId: ctx.userId }),
|
|
(w) => w.id
|
|
)
|
|
return ids.map((id) => results[id] || null)
|
|
}
|
|
),
|
|
/**
|
|
* Get workspace project count
|
|
*/
|
|
getProjectCount: createLoader<string, number | null>(async (ids) => {
|
|
const results = await getWorkspacesProjectsCounts({
|
|
workspaceIds: ids.slice()
|
|
})
|
|
return ids.map((id) => results[id])
|
|
})
|
|
},
|
|
workspaceDomains: {
|
|
/**
|
|
* Get workspace, with the active user's role attached
|
|
*/
|
|
getWorkspaceDomains: createLoader<string, WorkspaceDomain | null>(
|
|
async (ids) => {
|
|
const results = keyBy(
|
|
await getWorkspaceDomains({ workspaceIds: ids.slice() }),
|
|
(w) => w.id
|
|
)
|
|
return ids.map((id) => results[id] || null)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
export default FF_WORKSPACES_MODULE_ENABLED ? dataLoadersDefinition : undefined
|