feat: Updated collection header (#4101)

* Return total results from collection membership endpoints

* Display membership preview on collections

* fix permissions

* Revert unneccessary changes
This commit is contained in:
Tom Moor
2022-09-11 14:54:57 +02:00
committed by GitHub
parent 3aa7f34a73
commit 0fd576cdd5
19 changed files with 267 additions and 165 deletions

View File

@@ -316,22 +316,26 @@ router.post(
where = { ...where, permission };
}
const memberships = await CollectionGroup.findAll({
where,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
include: [
{
model: Group,
as: "group",
where: groupWhere,
required: true,
},
],
});
const [total, memberships] = await Promise.all([
CollectionGroup.count({ where }),
CollectionGroup.findAll({
where,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
include: [
{
model: Group,
as: "group",
where: groupWhere,
required: true,
},
],
}),
]);
ctx.body = {
pagination: ctx.state.pagination,
pagination: { ...ctx.state.pagination, total },
data: {
collectionGroupMemberships: memberships.map(
presentCollectionGroupMembership
@@ -457,23 +461,26 @@ router.post("collections.memberships", auth(), pagination(), async (ctx) => {
where = { ...where, permission };
}
const memberships = await CollectionUser.findAll({
where,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
include: [
{
model: User,
as: "user",
where: userWhere,
required: true,
},
],
});
const [total, memberships] = await Promise.all([
CollectionUser.count({ where }),
CollectionUser.findAll({
where,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
include: [
{
model: User,
as: "user",
where: userWhere,
required: true,
},
],
}),
]);
ctx.body = {
pagination: ctx.state.pagination,
pagination: { ...ctx.state.pagination, total },
data: {
memberships: memberships.map(presentMembership),
users: memberships.map((membership) => presentUser(membership.user)),