Skip to content

Commit

Permalink
Minor Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jul 8, 2024
1 parent 2543b7e commit db87aee
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/client/dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"), {
Expand Down
8 changes: 2 additions & 6 deletions code/client/src/domain/workspaces/useWorkspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ function useWorkspaces() {
const service = useWorkspaceService();
const [workspaces, setWorkspaces] = useState<WorkspaceMeta[]>([]);

function onCreateWorkspace(workspace: WorkspaceMeta) {
setWorkspaces([...workspaces, workspace]);
}

function onDeleteWorkspace(id: string) {
setWorkspaces(workspaces.filter(workspace => workspace.id !== id));
}
Expand All @@ -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) {
Expand All @@ -54,7 +51,6 @@ function useWorkspaces() {
}

useSocketListeners(socket, {
createdWorkspace: onCreateWorkspace,
deletedWorkspace: onDeleteWorkspace,
updatedWorkspace: onUpdateWorkspace,
});
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/services/workspace/workspaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function workspaceService(http: HttpCommunication, errorHandler: ErrorHandler) {
return errorHandler(async () => await http.get('/workspaces'));
}

async function createWorkspace(workspace: WorkspaceInputModel): Promise<string> {
async function createWorkspace(workspace: WorkspaceInputModel): Promise<WorkspaceMeta> {
return errorHandler(async () => await http.post('/workspaces', workspace));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion code/server/src/databases/memory/MemoryWorkspacesDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export class MemoryWorkspacesDB implements WorkspacesRepository {
}

async getWorkspaces(email?: string): Promise<WorkspaceMeta[]> {
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) || [] };
Expand Down
4 changes: 3 additions & 1 deletion code/server/test/workspaces/members.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit db87aee

Please sign in to comment.