mirror of
https://github.com/outline/outline.git
synced 2026-11-28 16:19:46 +03:00
Add missing total to groupMemberships pagination (#10589)
* Add missing total to groupMembership pagination closes #10499 * test
This commit is contained in:
1 parent
b925854247
commit
72bf9b86f6
2 files changed
+64
-2
No files matched your search
@@ -67,4 +67,64 @@ describe("groupMemberships.list", () => {
|
||||
expect(body.data.groupMemberships[0].groupId).toEqual(group.id);
|
||||
expect(body.policies).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it("should return total count in pagination", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
permission: null,
|
||||
});
|
||||
const group = await buildGroup({
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const member = await buildUser({
|
||||
teamId: user.teamId,
|
||||
});
|
||||
await GroupUser.create({
|
||||
groupId: group.id,
|
||||
userId: member.id,
|
||||
createdById: user.id,
|
||||
});
|
||||
|
||||
// Create 3 documents and share them with the group
|
||||
const documents = await Promise.all([
|
||||
buildDocument({
|
||||
collectionId: collection.id,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
}),
|
||||
buildDocument({
|
||||
collectionId: collection.id,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
}),
|
||||
buildDocument({
|
||||
collectionId: collection.id,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
}),
|
||||
]);
|
||||
|
||||
for (const document of documents) {
|
||||
await server.post("/api/documents.add_group", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
id: document.id,
|
||||
groupId: group.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const res = await server.post("/api/groupMemberships.list", {
|
||||
body: {
|
||||
token: member.getJwtToken(),
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.pagination).not.toBeFalsy();
|
||||
expect(body.pagination.total).toEqual(3);
|
||||
expect(body.data.groupMemberships).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
@@ -26,7 +26,9 @@ router.post(
|
||||
const { user } = ctx.state.auth;
|
||||
const userId = user.id;
|
||||
|
||||
const memberships = await GroupMembership.findAll({
|
||||
const { count, rows: memberships } = await GroupMembership.findAndCountAll({
|
||||
distinct: true,
|
||||
col: "id",
|
||||
where: {
|
||||
documentId: {
|
||||
[Op.ne]: null,
|
||||
@@ -77,7 +79,7 @@ router.post(
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
pagination: { ...ctx.state.pagination, total: count },
|
||||
data: {
|
||||
groups: await Promise.all(groups.map(presentGroup)),
|
||||
groupMemberships: memberships.map(presentGroupMembership),
|
||||
|
||||
Reference in new issue
Block a user