Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhermeF03 committed Jun 25, 2024
2 parents d9d13b2 + b1598f4 commit 2780b34
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions code/server/src/databases/memory/MemoryWorkspacesDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class MemoryWorkspacesDB implements WorkspacesRepository {
return id;
}

async getWorkspaces(userId: string): Promise<WorkspaceMeta[]> {
async getWorkspaces(userId?: string): Promise<WorkspaceMeta[]> {
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 };
Expand Down
5 changes: 3 additions & 2 deletions code/server/src/databases/postgres/PostgresWorkspacesDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export class PostgresWorkspacesDB implements WorkspacesRepository {
return results[0].id;
}

async getWorkspaces(userId: string): Promise<WorkspaceMeta[]> {
async getWorkspaces(userId?: string): Promise<WorkspaceMeta[]> {
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
Expand Down
6 changes: 4 additions & 2 deletions code/server/src/databases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ export interface WorkspacesRepository {
*/
createWorkspace: (name: string, isPrivate: boolean) => Promise<string>;
/**
* 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<WorkspaceMeta[]>;
getWorkspaces: (userId?: string) => Promise<WorkspaceMeta[]>;
/**
* Get a workspace from the database
* @param id
Expand Down
2 changes: 1 addition & 1 deletion code/server/src/services/WorkspacesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class WorkspacesService {
await this.databases.documents.removeWorkspace(id);
}

async getWorkspaces(userId: string): Promise<WorkspaceMeta[]> {
async getWorkspaces(userId?: string): Promise<WorkspaceMeta[]> {
return await this.databases.workspaces.getWorkspaces(userId);
}

Expand Down

0 comments on commit 2780b34

Please sign in to comment.