35e99d6ee7
* wip * feat(workspaces): preflight service wip * feat(workspaces): move project to workspace dry run * fix(workspaces): add tests and refine query * chore(workspaces): gqlgen
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import { db } from '@/db/knex'
|
|
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
|
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
|
|
import { getPaginatedItemsFactory } from '@/modules/shared/services/paginatedItems'
|
|
import { WorkspaceTeamMember } from '@/modules/workspaces/domain/types'
|
|
import { intersectProjectCollaboratorsAndWorkspaceCollaboratorsFactory } from '@/modules/workspaces/repositories/projects'
|
|
import {
|
|
countInvitableCollaboratorsByProjectIdFactory,
|
|
getInvitableCollaboratorsByProjectIdFactory
|
|
} from '@/modules/workspaces/repositories/users'
|
|
import { getMoveProjectToWorkspaceDryRunFactory } from '@/modules/workspaces/services/projects'
|
|
|
|
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
|
|
|
|
export default FF_WORKSPACES_MODULE_ENABLED
|
|
? ({
|
|
Project: {
|
|
invitableCollaborators: async (parent, args) => {
|
|
// TODO: add authz policy
|
|
if (!parent.workspaceId) {
|
|
return {
|
|
totalCount: 0,
|
|
items: [],
|
|
cursor: null
|
|
}
|
|
}
|
|
|
|
return await getPaginatedItemsFactory<
|
|
{
|
|
limit: number
|
|
cursor?: string
|
|
filter: {
|
|
workspaceId: string
|
|
projectId: string
|
|
search?: string
|
|
}
|
|
},
|
|
WorkspaceTeamMember
|
|
>({
|
|
getItems: getInvitableCollaboratorsByProjectIdFactory({ db }),
|
|
getTotalCount: countInvitableCollaboratorsByProjectIdFactory({ db })
|
|
})({
|
|
filter: {
|
|
workspaceId: parent.workspaceId,
|
|
projectId: parent.id,
|
|
search: args.filter?.search ?? undefined
|
|
},
|
|
cursor: args.cursor ?? undefined,
|
|
limit: args.limit
|
|
})
|
|
},
|
|
moveToWorkspaceDryRun: async (parent, args) => {
|
|
const { id: projectId } = parent
|
|
const { workspaceId } = args
|
|
|
|
const { addedToWorkspace } = await getMoveProjectToWorkspaceDryRunFactory({
|
|
intersectProjectCollaboratorsAndWorkspaceCollaborators:
|
|
intersectProjectCollaboratorsAndWorkspaceCollaboratorsFactory({ db })
|
|
})({ projectId, workspaceId })
|
|
|
|
return addedToWorkspace
|
|
}
|
|
},
|
|
ProjectMoveToWorkspaceDryRun: {
|
|
addedToWorkspace: async (parent, args) => {
|
|
return args.limit ? parent.slice(0, args.limit) : parent
|
|
},
|
|
addedToWorkspaceTotalCount: async (parent) => {
|
|
return parent.length
|
|
}
|
|
}
|
|
} as Resolvers)
|
|
: {}
|