From b21400c613224e48efef97327d48f2e55b890d63 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:31:46 +0530 Subject: [PATCH] fix: show seated attendees to host even when seatsShowAttendees is disabled (#22565) * fix: show attendee * Update get.handler.ts * update --- .../routers/viewer/bookings/get.handler.ts | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/trpc/server/routers/viewer/bookings/get.handler.ts b/packages/trpc/server/routers/viewer/bookings/get.handler.ts index 20646a71fa..2a08b5e4e7 100644 --- a/packages/trpc/server/routers/viewer/bookings/get.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/get.handler.ts @@ -503,6 +503,20 @@ export async function getBookings({ "varchar" // Or 'text' - use the actual SQL data type ) .as("schedulingType"), + jsonArrayFrom( + eb + .selectFrom("Host") + .select((eb) => [ + "Host.userId", + jsonObjectFrom( + eb + .selectFrom("users") + .select(["users.id", "users.email"]) + .whereRef("Host.userId", "=", "users.id") + ).as("user"), + ]) + .whereRef("Host.eventTypeId", "=", "EventType.id") + ).as("hosts"), "EventType.length", jsonObjectFrom( eb @@ -640,10 +654,29 @@ export async function getBookings({ }) ); + const checkIfUserIsHost = (userId: number, booking: (typeof plainBookings)[number]) => { + if (booking.user?.id === userId) { + return true; + } + + if (!booking.eventType?.hosts || booking.eventType.hosts.length === 0) { + return false; + } + + const attendeeEmails = new Set(booking.attendees.map((attendee) => attendee.email)); + + return booking.eventType.hosts.some(({ user: hostUser }) => { + return hostUser?.id === userId && attendeeEmails.has(hostUser.email); + }); + }; const bookings = await Promise.all( plainBookings.map(async (booking) => { - // If seats are enabled and the event is not set to show attendees, filter out attendees that are not the current user - if (booking.seatsReferences.length && !booking.eventType?.seatsShowAttendees) { + // If seats are enabled, the event is not set to show attendees, and the current user is not the host, filter out attendees who are not the current user + if ( + booking.seatsReferences.length && + !booking.eventType?.seatsShowAttendees && + !checkIfUserIsHost(user.id, booking) + ) { booking.attendees = booking.attendees.filter((attendee) => attendee.email === user.email); }