Skip to content

Commit

Permalink
fix: Show managed event bookings for team admins/owners (#18434)
Browse files Browse the repository at this point in the history
* add managed event bookings for team admins/owners

* remove unnecessary OR

* address change suggestion

* improve readability
  • Loading branch information
alishaz-polymath authored Jan 3, 2025
1 parent aa0b3a2 commit bd61e01
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions packages/trpc/server/routers/viewer/bookings/get.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,33 @@ export async function getBookings({
},
};

const membershipIdsWhereUserIsAdminOwner = (
await prisma.membership.findMany({
where: {
userId: user.id,
role: {
in: ["ADMIN", "OWNER"],
},
},
select: {
id: true,
},
})
).map((membership) => membership.id);

const membershipConditionWhereUserIsAdminOwner = {
some: {
id: { in: membershipIdsWhereUserIsAdminOwner },
},
};

const [
// Quering these in parallel to save time.
// Note that because we are applying `take` to individual queries, we will usually get more bookings then we need. It is okay to have more bookings faster than having what we need slower
bookingsQueryUserId,
bookingsQueryAttendees,
bookingsQueryTeamMember,
bookingsQueryManagedEvents,
bookingsQueryOrganizationMembers,
bookingsQuerySeatReference,
//////////////////////////
Expand Down Expand Up @@ -337,14 +358,7 @@ export async function getBookings({
{
eventType: {
team: {
members: {
some: {
userId: user.id,
role: {
in: ["ADMIN", "OWNER"],
},
},
},
members: membershipConditionWhereUserIsAdminOwner,
},
},
},
Expand All @@ -355,6 +369,21 @@ export async function getBookings({
take: take + 1,
skip,
}),
prisma.booking.findMany({
where: {
eventType: {
parent: {
team: {
members: membershipConditionWhereUserIsAdminOwner,
},
},
},
AND: [passedBookingsStatusFilter, ...filtersCombined],
},
orderBy,
take: take + 1,
skip,
}),
prisma.booking.findMany({
where: {
OR: [
Expand All @@ -364,14 +393,7 @@ export async function getBookings({
some: {
team: {
isOrganization: true,
members: {
some: {
userId: user.id,
role: {
in: ["ADMIN", "OWNER"],
},
},
},
members: membershipConditionWhereUserIsAdminOwner,
},
},
},
Expand Down Expand Up @@ -468,6 +490,7 @@ export async function getBookings({
bookingsQueryUserId
.concat(bookingsQueryAttendees)
.concat(bookingsQueryTeamMember)
.concat(bookingsQueryManagedEvents)
.concat(bookingsQueryOrganizationMembers)
.concat(bookingsQuerySeatReference)
);
Expand Down

0 comments on commit bd61e01

Please sign in to comment.