Files
speckle-server/packages/server/modules/workspaces/services/projects.ts
T
andrewwallacespeckle e3f90377b5 feat(fe2): workspace project list (#2616)
* Create and Use ProjectList

* ProjectList and WorkspaceList

* Workspace Header

* Header Actions Menu

* Add projects to Workspace

* Add middleware

* Remove unused title

* Rename WorkspaceList

* useDebouncedSearch

* Merge ProjectList into Dashboard

* Make workspaceId reactive

* Remove unneeded useSubscription

* Merge Dashboard into index

* Add fragments

* Cache updates

* gql

* GQL

* Linting updates

* Updates from CR

* Changes from CR

* Changes from PR. Middleware added

* Updates from CR

* GQL

* Updates from CR

* Updates from CR

* Updates from CR

* Add id to WorkspaceHeader_Workspace

* GQL

* Fragment naming

* Use identifier

* Comment buttons not yet ready

* Fix problem with pagination
2024-08-14 15:21:38 +01:00

79 lines
2.2 KiB
TypeScript

import { StreamRecord } from '@/modules/core/helpers/types'
import { convertDateToCursor, parseCursorToDate } from '@/modules/core/services/admin'
import { getStreams as serviceGetStreams } from '@/modules/core/services/streams'
import { QueryAllWorkspaceProjects } from '@/modules/workspaces/domain/operations'
import { WorkspaceQueryError } from '@/modules/workspaces/errors/workspace'
export const queryAllWorkspaceProjectsFactory = ({
getStreams
}: {
// TODO: Core service factory functions
getStreams: typeof serviceGetStreams
}): QueryAllWorkspaceProjects =>
async function* queryAllWorkspaceProjects({
workspaceId
}): AsyncGenerator<StreamRecord[], void, unknown> {
let cursor: Date | null = null
let iterationCount = 0
do {
if (iterationCount > 500) throw new WorkspaceQueryError()
const { streams, cursorDate } = await getStreams({
cursor,
orderBy: null,
limit: 1000,
visibility: null,
searchQuery: null,
streamIdWhitelist: null,
workspaceIdWhitelist: [workspaceId]
})
yield streams
cursor = cursorDate
iterationCount++
} while (!!cursor)
}
type GetWorkspaceProjectsArgs = {
workspaceId: string
}
type GetWorkspaceProjectsOptions = {
limit: number | null
cursor: string | null
filter: {
search?: string | null
} | null
}
type GetWorkspaceProjectsReturnValue = {
items: StreamRecord[]
cursor: string | null
totalCount: number
}
export const getWorkspaceProjectsFactory =
({ getStreams }: { getStreams: typeof serviceGetStreams }) =>
async (
args: GetWorkspaceProjectsArgs,
opts: GetWorkspaceProjectsOptions
): Promise<GetWorkspaceProjectsReturnValue> => {
const { streams, cursorDate, totalCount } = await getStreams({
cursor: opts.cursor ? parseCursorToDate(opts.cursor) : null,
orderBy: null,
limit: opts.limit || 25,
visibility: null,
searchQuery: opts.filter?.search || null,
streamIdWhitelist: null,
workspaceIdWhitelist: [args.workspaceId]
})
return {
items: streams,
cursor: cursorDate ? convertDateToCursor(cursorDate) : null,
totalCount
}
}