diff --git a/code/client/src/domain/editor/fugue/Fugue.ts b/code/client/src/domain/editor/fugue/Fugue.ts index ef4c65c3..a2e2a811 100644 --- a/code/client/src/domain/editor/fugue/Fugue.ts +++ b/code/client/src/domain/editor/fugue/Fugue.ts @@ -98,7 +98,7 @@ export class Fugue { * Inserts a new node in the tree based on the given operation. * @param operation */ - private addNode = ({id, value, line, styles, parent, side}: InsertOperation) => { + private addNode = ({ id, value, line, styles, parent, side }: InsertOperation) => { this.tree.addNode(id, value, parent, side, styles, line); }; @@ -302,7 +302,7 @@ export class Fugue { getLineRoot = (line: number): FugueNode => { return line === 0 ? this.tree.root : this.tree.root.value[line - 1]; - } + }; /** * Returns the string representation of the tree. diff --git a/code/client/src/domain/editor/fugue/FugueTree.ts b/code/client/src/domain/editor/fugue/FugueTree.ts index 5d6ca17e..d9ca0ad0 100644 --- a/code/client/src/domain/editor/fugue/FugueTree.ts +++ b/code/client/src/domain/editor/fugue/FugueTree.ts @@ -32,11 +32,11 @@ export class FugueTree { * @param styles the styles of the node * @param line */ - addNode(id: Id, value: T, parent: Id, side: 'L' | 'R', styles: InlineStyle[] | undefined, line: number){ + addNode(id: Id, value: T, parent: Id, side: 'L' | 'R', styles: InlineStyle[] | undefined, line: number) { // create node - const node : Node = treeNode(id, value, parent, side, 0, styles as InlineStyle[]); - if(value === '\n') { - this._root.value.splice(line, 0, node); // TODO: check if this is correct + const node: Node = treeNode(id, value, parent, side, 0, styles as InlineStyle[]); + if (value === '\n') { + this._root.value.splice(line, 0, node); // TODO: check if this is correct } this._addNode(node); } diff --git a/code/server/src/databases/memory/MemoryWorkspacesDB.ts b/code/server/src/databases/memory/MemoryWorkspacesDB.ts index 42d40bba..33a00e9d 100644 --- a/code/server/src/databases/memory/MemoryWorkspacesDB.ts +++ b/code/server/src/databases/memory/MemoryWorkspacesDB.ts @@ -29,9 +29,9 @@ export class MemoryWorkspacesDB implements WorkspacesRepository { return id; } - async getWorkspaces(userId: string): Promise { + async getWorkspaces(userId?: string): Promise { return Object.values(Memory.workspaces) - .filter(workspace => !workspace.isPrivate || workspace.members.includes(userId)) + .filter(workspace => !workspace.isPrivate || (userId && workspace.members.includes(userId))) .map(props => { const workspace = omit(props, ['resources']); return { ...workspace, members: workspace.members?.length || 0 }; diff --git a/code/server/src/databases/postgres/PostgresWorkspacesDB.ts b/code/server/src/databases/postgres/PostgresWorkspacesDB.ts index 7a608c9a..07088edf 100644 --- a/code/server/src/databases/postgres/PostgresWorkspacesDB.ts +++ b/code/server/src/databases/postgres/PostgresWorkspacesDB.ts @@ -17,14 +17,15 @@ export class PostgresWorkspacesDB implements WorkspacesRepository { return results[0].id; } - async getWorkspaces(userId: string): Promise { + async getWorkspaces(userId?: string): Promise { + const user = userId || null; return ( await sql` select row_to_json(t) as workspace from ( select id, name, private, count(members) as members from workspace - where private = false or ${userId} = any(members) + where private = false or (${user} is null or ${user} = any(members)) group by id order by created_at desc ) as t diff --git a/code/server/src/databases/types.ts b/code/server/src/databases/types.ts index c6b43b27..4f9eb4fe 100644 --- a/code/server/src/databases/types.ts +++ b/code/server/src/databases/types.ts @@ -79,9 +79,11 @@ export interface WorkspacesRepository { */ createWorkspace: (name: string, isPrivate: boolean) => Promise; /** - * Get all workspaces from the database that the user can access + * Get all workspaces from the database + * If userId is provided, get user workspaces + * @param userId */ - getWorkspaces: (userId: string) => Promise; + getWorkspaces: (userId?: string) => Promise; /** * Get a workspace from the database * @param id diff --git a/code/server/src/services/WorkspacesService.ts b/code/server/src/services/WorkspacesService.ts index 10f8d11e..cde555a6 100644 --- a/code/server/src/services/WorkspacesService.ts +++ b/code/server/src/services/WorkspacesService.ts @@ -30,7 +30,7 @@ export class WorkspacesService { await this.databases.documents.removeWorkspace(id); } - async getWorkspaces(userId: string): Promise { + async getWorkspaces(userId?: string): Promise { return await this.databases.workspaces.getWorkspaces(userId); }