Skip to content

Commit

Permalink
Add controller for retrieving workspace members
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 18, 2024
1 parent aec14b0 commit 7a3b9a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 39 additions & 3 deletions backend/src/workspace-users/workspace-users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
import { Controller } from "@nestjs/common";
import { Controller, DefaultValuePipe, Get, Param, ParseIntPipe, Query, Req } from "@nestjs/common";
import { ApiBearerAuth, ApiFoundResponse, ApiOperation, ApiQuery, ApiTags } from "@nestjs/swagger";
import { FindWorkspaceUsersResponse } from "./types/find-workspace-users-response.type";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { WorkspaceUsersService } from "./workspace-users.service";

@Controller("workspace-users")
export class WorkspaceUsersController {}
@ApiTags("Workspace.Users")
@ApiBearerAuth()
@Controller("workspaces/:workspace_id/users")
export class WorkspaceUsersController {
constructor(private workspaceUsersService: WorkspaceUsersService) {}

@Get("")
@ApiOperation({
summary: "Retrieve the Users in Workspace",
description: "Return the users in the workspace. This API supports KeySet pagination.",
})
@ApiFoundResponse({ type: FindWorkspaceUsersResponse })
@ApiQuery({
name: "page_size",
type: Number,
description: "Page size to fetch (Default to 10)",
required: false,
})
@ApiQuery({
name: "cursor",
type: String,
description:
"API returns a limited set of results after a given cursor. If no value is provided, it returns the first page.",
required: false,
})
async findMany(
@Req() req: AuthroizedRequest,
@Param("workspace_id") workspaceId: string,
@Query("page_size", new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
@Query("cursor", new DefaultValuePipe(undefined)) cursor?: string
): Promise<FindWorkspaceUsersResponse> {
return this.workspaceUsersService.findMany(req.user.id, workspaceId, pageSize, cursor);
}
}
6 changes: 6 additions & 0 deletions backend/src/workspace-users/workspace-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class WorkspaceUsersService {

const workspaceUserList = await this.prismaService.user.findMany({
take: pageSize + 1,
select: {
id: true,
nickname: true,
updatedAt: true,
createdAt: true,
},
where: {
userWorkspaceList: {
some: {
Expand Down

0 comments on commit 7a3b9a8

Please sign in to comment.