Files
colanode/packages/client/src/handlers/mutations/spaces/space-create.ts
Hakan Shehu 3e4c8b8125 Implement new routing with tanstack router and mobile app kickoff (#248)
* Init mobile app
* Minor fixes and improvements
* Improve assets loading
* Fix event bus proxy
* Improve emojis and icons loading
* Improve app initialization in web
* Init tanstack router
* Refactor components
* Refactor some more components
* Refactor layouts
* Improve routing
* Improve routing
* Routing improvements
* Make sidebar work in mobile
* Refactor container and breadcrumb
* Fix some packages and warnings
* Encode and decode yjs update for ipc communication
* Refactor servers in client
* Fix some errors and warnings in editor and sidebar
* Add route masking for web
* Improve container layout
* Improve ui for mobile
* Improve mobile ui
* Create custom link component
* Router improvements
* Implement tabs for desktop
* tabs improvements
* Refactor routes
* Layout improvements
* Improve desktop tabs
* Use tanstack-db for global collections
* Improve tanstack db collections
* Refactor workspaces and accounts databases and routes locally
* Use tanstackdb for users
* Use tanstackdb for uploads and downloads
* Use tanstackdb for temp files
* Rename database to collections
* Improve tabs
* Fix packages
* Improve local file handling
* Rename sync cursor keys
* Save some bootstrap data in a file
* Reset all data on new version update in desktop
* Minor refactor
* Implement app reset on startup
* UI fixes and improvements
* More Ui improvements
* Fix logout
* Add tab in route contexts for workspace routes
* Store last used workspace id as metadata
* Fix account logout
* Fix file preview
* Fix file thumbnail loading in tabs
* Fix chat tab loading
* Fix some redirect handling
* Disable staletime for icon.svg.get query
* Fix not found pages and throws
* add readme for mobile
* fix some keys
* Improve add tab handler
* Fix path
2025-11-11 07:00:14 -08:00

88 lines
2.2 KiB
TypeScript

import { WorkspaceMutationHandlerBase } from '@colanode/client/handlers/mutations/workspace-mutation-handler-base';
import { MutationHandler } from '@colanode/client/lib/types';
import { MutationError, MutationErrorCode } from '@colanode/client/mutations';
import {
SpaceCreateMutationInput,
SpaceCreateMutationOutput,
} from '@colanode/client/mutations/spaces/space-create';
import {
ChannelAttributes,
generateId,
IdType,
PageAttributes,
SpaceAttributes,
} from '@colanode/core';
export class SpaceCreateMutationHandler
extends WorkspaceMutationHandlerBase
implements MutationHandler<SpaceCreateMutationInput>
{
async handleMutation(
input: SpaceCreateMutationInput
): Promise<SpaceCreateMutationOutput> {
const workspace = this.getWorkspace(input.userId);
if (!workspace) {
throw new MutationError(
MutationErrorCode.WorkspaceNotFound,
'Workspace was not found or has been deleted.'
);
}
if (workspace.role === 'guest' || workspace.role === 'none') {
throw new MutationError(
MutationErrorCode.SpaceCreateForbidden,
"You don't have permission to create spaces in this workspace."
);
}
const spaceId = generateId(IdType.Space);
const spaceAttributes: SpaceAttributes = {
type: 'space',
name: input.name,
visibility: 'private',
collaborators: {
[workspace.userId]: 'admin',
},
description: input.description,
avatar: input.avatar,
};
await workspace.nodes.createNode({
id: spaceId,
attributes: spaceAttributes,
parentId: null,
});
const pageId = generateId(IdType.Page);
const pageAttributes: PageAttributes = {
type: 'page',
name: 'Home',
parentId: spaceId,
};
await workspace.nodes.createNode({
id: pageId,
attributes: pageAttributes,
parentId: spaceId,
});
const channelId = generateId(IdType.Channel);
const channelAttributes: ChannelAttributes = {
type: 'channel',
name: 'Discussions',
parentId: spaceId,
};
await workspace.nodes.createNode({
id: channelId,
attributes: channelAttributes,
parentId: spaceId,
});
return {
id: spaceId,
};
}
}