diff --git a/packages/server/modules/workspaces/domain/operations.ts b/packages/server/modules/workspaces/domain/operations.ts index b954e73f7..2e786efdd 100644 --- a/packages/server/modules/workspaces/domain/operations.ts +++ b/packages/server/modules/workspaces/domain/operations.ts @@ -7,6 +7,8 @@ import { Workspace, WorkspaceAcl } from '@/modules/workspaces/domain/types' export type StoreWorkspace = (args: { workspace: Workspace }) => Promise export type UpsertWorkspaceRole = (args: WorkspaceAcl) => Promise +export type StoreBlob = (args: string) => Promise + export type EmitWorkspaceEvent = (args: { event: TEvent payload: WorkspaceEventsPayloads[TEvent] diff --git a/packages/server/modules/workspaces/services/workspaceCreation.ts b/packages/server/modules/workspaces/services/workspaceCreation.ts index 577a9c1d7..94672ab9f 100644 --- a/packages/server/modules/workspaces/services/workspaceCreation.ts +++ b/packages/server/modules/workspaces/services/workspaceCreation.ts @@ -1,5 +1,6 @@ import { EmitWorkspaceEvent, + StoreBlob, StoreWorkspace, UpsertWorkspaceRole } from '@/modules/workspaces/domain/operations' @@ -7,10 +8,8 @@ import { Workspace } from '@/modules/workspaces/domain/types' import { Roles } from '@speckle/shared' import cryptoRandomString from 'crypto-random-string' -// using Pick deliberately here, so if we change the Workspace domain model, we need to -// explicitly handle the changes here too type WorkspaceCreateArgs = { - workspaceInput: Pick + workspaceInput: { name: string; description: string | null; logo: string | null } userId: string } @@ -18,19 +17,27 @@ export const createWorkspaceFactory = ({ storeWorkspace, upsertWorkspaceRole, - emitWorkspaceEvent + emitWorkspaceEvent, + storeBlob }: { storeWorkspace: StoreWorkspace upsertWorkspaceRole: UpsertWorkspaceRole + storeBlob: StoreBlob emitWorkspaceEvent: EmitWorkspaceEvent }) => async ({ userId, workspaceInput }: WorkspaceCreateArgs): Promise => { + let logoUrl: string | null = null + if (workspaceInput.logo) { + logoUrl = await storeBlob(workspaceInput.logo) + } + const workspace = { ...workspaceInput, id: cryptoRandomString({ length: 10 }), createdAt: new Date(), updatedAt: new Date(), - createdByUserId: userId + createdByUserId: userId, + logoUrl } await storeWorkspace({ workspace }) // assign the creator as workspace administrator