diff --git a/code/client/dev-dist/sw.js b/code/client/dev-dist/sw.js index 5c80871..3c55ea7 100644 --- a/code/client/dev-dist/sw.js +++ b/code/client/dev-dist/sw.js @@ -82,7 +82,7 @@ define(['./workbox-b5f7729d'], (function (workbox) { 'use strict'; "revision": "3ca0b8505b4bec776b69afdba2768812" }, { "url": "index.html", - "revision": "0.mhatuu3dq7g" + "revision": "0.hcukrbetkmo" }], {}); workbox.cleanupOutdatedCaches(); workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { diff --git a/code/client/src/domain/workspaces/useWorkspaces.ts b/code/client/src/domain/workspaces/useWorkspaces.ts index 6b23a14..bda8555 100644 --- a/code/client/src/domain/workspaces/useWorkspaces.ts +++ b/code/client/src/domain/workspaces/useWorkspaces.ts @@ -9,10 +9,6 @@ function useWorkspaces() { const service = useWorkspaceService(); const [workspaces, setWorkspaces] = useState([]); - function onCreateWorkspace(workspace: WorkspaceMeta) { - setWorkspaces([...workspaces, workspace]); - } - function onDeleteWorkspace(id: string) { setWorkspaces(workspaces.filter(workspace => workspace.id !== id)); } @@ -29,7 +25,8 @@ function useWorkspaces() { } async function createWorkspace(workspace: WorkspaceInputModel) { - return await service.createWorkspace(workspace); + const workspaceCreated = await service.createWorkspace(workspace); + setWorkspaces([...workspaces, workspaceCreated]); } async function deleteWorkspace(id: string) { @@ -54,7 +51,6 @@ function useWorkspaces() { } useSocketListeners(socket, { - createdWorkspace: onCreateWorkspace, deletedWorkspace: onDeleteWorkspace, updatedWorkspace: onUpdateWorkspace, }); diff --git a/code/client/src/services/workspace/workspaceService.ts b/code/client/src/services/workspace/workspaceService.ts index fff86be..c422eba 100644 --- a/code/client/src/services/workspace/workspaceService.ts +++ b/code/client/src/services/workspace/workspaceService.ts @@ -13,7 +13,7 @@ function workspaceService(http: HttpCommunication, errorHandler: ErrorHandler) { return errorHandler(async () => await http.get('/workspaces')); } - async function createWorkspace(workspace: WorkspaceInputModel): Promise { + async function createWorkspace(workspace: WorkspaceInputModel): Promise { return errorHandler(async () => await http.post('/workspaces', workspace)); } diff --git a/code/server/src/controllers/http/handlers/workspacesHandlers.ts b/code/server/src/controllers/http/handlers/workspacesHandlers.ts index f27350f..2bacb55 100644 --- a/code/server/src/controllers/http/handlers/workspacesHandlers.ts +++ b/code/server/src/controllers/http/handlers/workspacesHandlers.ts @@ -24,8 +24,7 @@ function workspacesHandlers(services: Services, io: Server) { members: [req.user!.email], isPrivate, }; - io.emit('createdWorkspace', workspace); - httpResponse.created(res).json({ id }); + httpResponse.created(res).json(workspace); }; const getWorkspaces = async (req: Request, res: Response) => { diff --git a/code/server/src/databases/memory/MemoryWorkspacesDB.ts b/code/server/src/databases/memory/MemoryWorkspacesDB.ts index 6c16da5..5d3c232 100644 --- a/code/server/src/databases/memory/MemoryWorkspacesDB.ts +++ b/code/server/src/databases/memory/MemoryWorkspacesDB.ts @@ -30,8 +30,9 @@ export class MemoryWorkspacesDB implements WorkspacesRepository { } async getWorkspaces(email?: string): Promise { + const userId = email ? Object.values(Memory.users).find(user => user.email === email)?.id : undefined; return Object.values(Memory.workspaces) - .filter(workspace => (email ? workspace.members.includes(email) : !workspace.isPrivate)) + .filter(workspace => (userId ? workspace.members.includes(userId) : !workspace.isPrivate)) .map(props => { const w = omit(props, ['resources']); return { ...w, members: w.members?.map(id => Memory.users[id].email) || [] }; diff --git a/code/server/test/workspaces/members.test.ts b/code/server/test/workspaces/members.test.ts index 086de07..645707c 100644 --- a/code/server/test/workspaces/members.test.ts +++ b/code/server/test/workspaces/members.test.ts @@ -11,12 +11,14 @@ describe('Workspace members operations', () => { test('should add a member to a workspace', async () => { const { wid, email } = await createTestUserAndWorkspace(services); const workspace = await services.workspaces.getWorkspace(wid); + const userWorkspaces = await services.workspaces.getWorkspaces(email); + expect(workspace.members).toContain(email); + expect(userWorkspaces[0].id).toBe(wid); }); test('should remove a member from a workspace', async () => { const { wid, email } = await createTestUserAndWorkspace(services); - const workspace = await services.workspaces.getWorkspace(wid); expect(workspace.members).toContain(email);