Skip to content

Scheduling infrastructure for absolutely everyone.

fix: show seated attendees to host even when seatsShowAttendees is disabled (#22565)

Anik Dhabal Babub21400c61322
diff --git a/packages/trpc/server/routers/viewer/bookings/get.handler.ts b/packages/trpc/server/routers/viewer/bookings/get.handler.ts
index 20646a71fa6..2a08b5e4e70 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);
}