Files
speckle-server/packages/server/modules/workspaces/services/retrieval.ts
T
Chuck Driesler 6eaf3c8c92 feat(workspaces): cru(d) resolvers (#2521)
* feat(workspaces): drop createdByUserId from the dataschema

* feat(workspaces): repositories WIP

* merge

* protect against removing last admin in workspace

* quick impl and stub tests

* add tests

* services

* unit tests for role services

* feat(workspaces): authorize project creation if workspace specified

* feat(workspaces): emit project created event

* feat(workspaces): assign roles on project create in workspace

* feat(workspaces): update project roles when user added to workspace

* feat(workspaces): stencil gql resolvers

* fix(workspaces): lol lmao

* fix(workspaces): perform automatic project role update in service function

* fix(workspaces): also delete roles

* fix(workspaces): broke tests again oops

* fix(workspaces): update `onProjectCreated` listener to use new repo method

* fix(workspaces): use service function in event listener

* fix(workspaces): get workspace projects via existing stream repo functions

* fix(workspaces): roles mapping in domain, use enum

* feat(workspaces): stencil gql api and resolvers

* fix(workspaces): repair type reference in tests

* fix(workspaces): consolidate files, use different existing stream-getter

* fix(workspaces): more specific error

* fix(workspaces): roles and scopes

* fix(workspaces): yield per page

* fix(workspaces): some test dry

* fix(workspaces): superdry

* fix(workspaces): add scopes

* fix(workspaces): classic

* feat(workspaces): create workspace mutation

* feat(workspaces): I'm sure everything will be fine

* fix(workspaces): yep

* fix(workspaces): successful gql e2e test

* feat(workspaces): update workspace resolver

* chore(workspaces): update resolver test

* feat(workspaces): some retrieval resolvers

* chore(workspaces): tests for query resolvers

* fix(chore): revert temp test command change

* fix(workspaces): test structure and gql types

* fix(workspaces): validate user authz to perform some operations

* fix(workspaces): use existing test infrastructure

* fix(workspaces): stop `isPublic` check if authorizing a workspace resource

* fix(workspaces): better test hygiene

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2024-07-25 12:58:28 +01:00

39 lines
1.1 KiB
TypeScript

import {
GetWorkspace,
GetWorkspaceRolesForUser
} from '@/modules/workspaces/domain/operations'
import { Workspace } from '@/modules/workspacesCore/domain/types'
import { chunk, isNull } from 'lodash'
type GetWorkspacesForUserArgs = {
userId: string
}
export const getWorkspacesForUserFactory =
({
getWorkspace,
getWorkspaceRolesForUser
}: {
getWorkspace: GetWorkspace
getWorkspaceRolesForUser: GetWorkspaceRolesForUser
}) =>
async ({ userId }: GetWorkspacesForUserArgs): Promise<Workspace[]> => {
const workspaceRoles = await getWorkspaceRolesForUser({ userId })
const workspaces: Workspace[] = []
for (const workspaceRoleBatch of chunk(workspaceRoles, 20)) {
// TODO: Use `getWorkspaces`, which I saw Fabians already wrote in another PR
const workspacesBatch = await Promise.all(
workspaceRoleBatch.map(({ workspaceId }) => getWorkspace({ workspaceId }))
)
workspaces.push(
...workspacesBatch.filter(
(workspace): workspace is Workspace => !isNull(workspace)
)
)
}
return workspaces
}