diff --git a/src/modules/workspaces/domains/workspaces.domain.ts b/src/modules/workspaces/domains/workspaces.domain.ts index 41cbae0b..a53675f9 100644 --- a/src/modules/workspaces/domains/workspaces.domain.ts +++ b/src/modules/workspaces/domains/workspaces.domain.ts @@ -78,6 +78,8 @@ export class Workspace implements WorkspaceAttributes { defaultTeamId: this.defaultTeamId, avatar: this.avatar, workspaceUserId: this.workspaceUserId, + numberOfSeats: this.numberOfSeats, + setupCompleted: this.setupCompleted, createdAt: this.createdAt, updatedAt: this.updatedAt, }; diff --git a/src/modules/workspaces/dto/edit-workspace-details-dto.ts b/src/modules/workspaces/dto/edit-workspace-details-dto.ts index d967fe4e..b56bc572 100644 --- a/src/modules/workspaces/dto/edit-workspace-details-dto.ts +++ b/src/modules/workspaces/dto/edit-workspace-details-dto.ts @@ -21,4 +21,8 @@ export class EditWorkspaceDetailsDto { @IsString() @Length(0, 150) description?: Workspace['description']; + @IsOptional() + @IsString() + @Length(5, 255) + address?: Workspace['address']; } diff --git a/src/modules/workspaces/workspaces.controller.spec.ts b/src/modules/workspaces/workspaces.controller.spec.ts index ad11c5c8..7c927414 100644 --- a/src/modules/workspaces/workspaces.controller.spec.ts +++ b/src/modules/workspaces/workspaces.controller.spec.ts @@ -256,13 +256,18 @@ describe('Workspace Controller', () => { workspacesController.editWorkspaceDetails(workspace.id, user, { name: 'new name', description: 'new description', + address: 'new address', }), ).resolves.toBeUndefined(); expect(workspacesUsecases.editWorkspaceDetails).toHaveBeenCalledWith( workspace.id, user, - { name: 'new name' }, + { + name: 'new name', + description: 'new description', + address: 'new address', + }, ); }); }); @@ -590,4 +595,19 @@ describe('Workspace Controller', () => { ); }); }); + + describe('GET /:workspaceId', () => { + it('When a workspace is requested, then it should return the workspace data', async () => { + const user = newUser(); + const workspace = newWorkspace(); + + jest + .spyOn(workspacesUsecases, 'getWorkspaceDetails') + .mockResolvedValueOnce(workspace.toJSON()); + + await expect( + workspacesController.getWorkspaceDetails(workspace.id, user), + ).resolves.toEqual(workspace.toJSON()); + }); + }); }); diff --git a/src/modules/workspaces/workspaces.controller.ts b/src/modules/workspaces/workspaces.controller.ts index a511bd95..8b3bafdc 100644 --- a/src/modules/workspaces/workspaces.controller.ts +++ b/src/modules/workspaces/workspaces.controller.ts @@ -958,4 +958,23 @@ export class WorkspacesController { workspaceId, ); } + + @Get(':workspaceId') + @ApiBearerAuth() + @ApiOperation({ + summary: 'Get workspace details', + }) + @ApiParam({ name: 'workspaceId', type: String, required: true }) + @ApiOkResponse({ + description: 'Workspace details', + }) + @UseGuards(WorkspaceGuard) + @WorkspaceRequiredAccess(AccessContext.WORKSPACE, WorkspaceRole.MEMBER) + async getWorkspaceDetails( + @Param('workspaceId', ValidateUUIDPipe) + workspaceId: WorkspaceAttributes['id'], + @UserDecorator() user: User, + ) { + return this.workspaceUseCases.getWorkspaceDetails(workspaceId); + } } diff --git a/src/modules/workspaces/workspaces.usecase.spec.ts b/src/modules/workspaces/workspaces.usecase.spec.ts index e374e1ec..7d60982d 100644 --- a/src/modules/workspaces/workspaces.usecase.spec.ts +++ b/src/modules/workspaces/workspaces.usecase.spec.ts @@ -340,12 +340,34 @@ describe('WorkspacesUsecases', () => { }); }); + describe('getWorkspaceDetails', () => { + it('When workspace does not exist, then it should throw', async () => { + jest.spyOn(workspaceRepository, 'findById').mockResolvedValueOnce(null); + + await expect(service.getWorkspaceDetails(v4())).rejects.toThrow( + NotFoundException, + ); + }); + + it('When workspace exists, then it should return the workspace details', async () => { + const workspace = newWorkspace(); + jest + .spyOn(workspaceRepository, 'findById') + .mockResolvedValueOnce(workspace); + + const result = await service.getWorkspaceDetails(workspace.id); + + expect(result).toEqual(workspace.toJSON()); + }); + }); + describe('editWorkspaceDetails', () => { const user = newUser(); const workspace = newWorkspace({ owner: user }); const editWorkspaceDto: EditWorkspaceDetailsDto = { name: 'Test Workspace', description: 'Workspace description', + address: 'Workspace Address', }; it('When workspace does not exist, then it should throw', async () => { jest.spyOn(workspaceRepository, 'findById').mockResolvedValueOnce(null); diff --git a/src/modules/workspaces/workspaces.usecase.ts b/src/modules/workspaces/workspaces.usecase.ts index 2c5b17b3..ee749811 100644 --- a/src/modules/workspaces/workspaces.usecase.ts +++ b/src/modules/workspaces/workspaces.usecase.ts @@ -169,6 +169,16 @@ export class WorkspacesUsecases { } } + async getWorkspaceDetails(workspaceId: Workspace['id']) { + const workspace = await this.workspaceRepository.findById(workspaceId); + + if (!workspace) { + throw new NotFoundException('Workspace not found'); + } + + return workspace.toJSON(); + } + async setupWorkspace( user: User, workspaceId: WorkspaceAttributes['id'],