-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service for retrieve workspace members
- Loading branch information
Showing
6 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/workspace-users/types/find-workspace-users-response.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { WorkspaceUserDomain } from "./workspace-user.domain"; | ||
|
||
export class FindWorkspaceUsersResponse { | ||
@ApiProperty({ type: [WorkspaceUserDomain], description: "List of found workspace users" }) | ||
workspaceUsers: Array<WorkspaceUserDomain>; | ||
|
||
@ApiProperty({ type: String, description: "The ID of last workspace user" }) | ||
cursor: string | null; | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/workspace-users/types/workspace-user.domain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
|
||
export class WorkspaceUserDomain { | ||
@ApiProperty({ type: String, description: "ID of the user" }) | ||
id: string; | ||
@ApiProperty({ type: String, description: "Nickname of the user" }) | ||
nickname: string; | ||
@ApiProperty({ type: Date, description: "Created date of the user" }) | ||
createdAt: Date; | ||
@ApiProperty({ type: Date, description: "Updated date of the user" }) | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { WorkspaceUsersController } from "./workspace-users.controller"; | ||
import { WorkspaceUsersService } from "./workspace-users.service"; | ||
import { PrismaService } from "src/db/prisma.service"; | ||
|
||
@Module({ | ||
controllers: [WorkspaceUsersController], | ||
providers: [WorkspaceUsersService], | ||
providers: [WorkspaceUsersService, PrismaService], | ||
}) | ||
export class WorkspaceUsersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,55 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { Injectable, NotFoundException } from "@nestjs/common"; | ||
import { Prisma } from "@prisma/client"; | ||
import { PrismaService } from "src/db/prisma.service"; | ||
import { FindWorkspaceUsersResponse } from "./types/find-workspace-users-response.type"; | ||
|
||
@Injectable() | ||
export class WorkspaceUsersService {} | ||
export class WorkspaceUsersService { | ||
constructor(private prismaService: PrismaService) {} | ||
|
||
async findMany( | ||
userId: string, | ||
workspaceId: string, | ||
pageSize: number, | ||
cursor?: string | ||
): Promise<FindWorkspaceUsersResponse> { | ||
try { | ||
await this.prismaService.userWorkspace.findFirstOrThrow({ | ||
where: { | ||
userId, | ||
workspaceId, | ||
}, | ||
}); | ||
} catch (e) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
const additionalOptions: Prisma.UserFindManyArgs = {}; | ||
|
||
if (cursor) { | ||
additionalOptions.cursor = { id: cursor }; | ||
} | ||
|
||
const workspaceUserList = await this.prismaService.user.findMany({ | ||
take: pageSize + 1, | ||
where: { | ||
userWorkspaceList: { | ||
some: { | ||
workspaceId: { | ||
equals: workspaceId, | ||
}, | ||
}, | ||
}, | ||
}, | ||
orderBy: { | ||
id: "desc", | ||
}, | ||
...additionalOptions, | ||
}); | ||
|
||
return { | ||
workspaceUsers: workspaceUserList.slice(0, pageSize), | ||
cursor: workspaceUserList.length > pageSize ? workspaceUserList[pageSize].id : null, | ||
}; | ||
} | ||
} |