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

* fix: show attendee

* Update get.handler.ts

* update
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2025-07-29 11:01:46 +01:00
1 parent 6c936472d2
commit b21400c613
1 file changed
+35 -2
@@ -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);
}