feat: support pagination for member list (#4231)

This commit is contained in:
Qi
2023-09-12 11:37:59 +08:00
committed by GitHub
parent 9fe9efe465
commit 98429bf89e
21 changed files with 404 additions and 108 deletions

View File

@@ -177,7 +177,6 @@ export class WorkspaceResolver {
return this.prisma.userWorkspacePermission.count({
where: {
workspaceId: workspace.id,
accepted: true,
},
});
}
@@ -210,15 +209,25 @@ export class WorkspaceResolver {
description: 'Members of workspace',
complexity: 2,
})
async members(@Parent() workspace: WorkspaceType) {
async members(
@Parent() workspace: WorkspaceType,
@Args('skip', { type: () => Int, nullable: true }) skip?: number,
@Args('take', { type: () => Int, nullable: true }) take?: number
) {
const data = await this.prisma.userWorkspacePermission.findMany({
where: {
workspaceId: workspace.id,
},
skip,
take: take || 8,
orderBy: {
type: 'desc',
},
include: {
user: true,
},
});
return data
.filter(({ user }) => !!user)
.map(({ id, accepted, type, user }) => ({

View File

@@ -98,7 +98,7 @@ type WorkspaceType {
createdAt: DateTime!
"""Members of workspace"""
members: [InviteUserType!]!
members(skip: Int, take: Int): [InviteUserType!]!
"""Permission of current signed in user in workspace"""
permission: Permission!

View File

@@ -119,7 +119,9 @@ export async function getWorkspaceSharedPages(
async function getWorkspace(
app: INestApplication,
token: string,
workspaceId: string
workspaceId: string,
skip = 0,
take = 8
): Promise<WorkspaceType> {
const res = await request(app.getHttpServer())
.post(gql)
@@ -129,7 +131,7 @@ async function getWorkspace(
query: `
query {
workspace(id: "${workspaceId}") {
id, members { id, name, email, permission, inviteId }
id, members(skip: ${skip}, take: ${take}) { id, name, email, permission, inviteId }
}
}
`,

View File

@@ -247,3 +247,34 @@ test('should send email', async t => {
}
t.pass();
});
test('should support pagination for member', async t => {
const { app } = t.context;
const u1 = await signUp(app, 'u1', 'u1@affine.pro', '1');
const u2 = await signUp(app, 'u2', 'u2@affine.pro', '1');
const u3 = await signUp(app, 'u3', 'u3@affine.pro', '1');
const workspace = await createWorkspace(app, u1.token.token);
await inviteUser(app, u1.token.token, workspace.id, u2.email, 'Admin');
await inviteUser(app, u1.token.token, workspace.id, u3.email, 'Admin');
await acceptInvite(app, u2.token.token, workspace.id);
await acceptInvite(app, u3.token.token, workspace.id);
const firstPageWorkspace = await getWorkspace(
app,
u1.token.token,
workspace.id,
0,
2
);
t.is(firstPageWorkspace.members.length, 2, 'failed to check invite id');
const secondPageWorkspace = await getWorkspace(
app,
u1.token.token,
workspace.id,
2,
2
);
t.is(secondPageWorkspace.members.length, 1, 'failed to check invite id');
});