From 3d02df3b08ffb408baf1a5eead77031bec6ff1fa Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:45:27 +0530 Subject: [PATCH] fix: use correct organizer info when admin accepts team booking requiring confirmation (#20612) * fix: confrim handler * fix test --- apps/web/playwright/webhook.e2e.ts | 2 +- .../viewer/bookings/confirm.handler.ts | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/web/playwright/webhook.e2e.ts b/apps/web/playwright/webhook.e2e.ts index 3ae55398a0..2edb7d1326 100644 --- a/apps/web/playwright/webhook.e2e.ts +++ b/apps/web/playwright/webhook.e2e.ts @@ -191,7 +191,7 @@ test.describe("BOOKING_REJECTED", async () => { endTime: "[redacted/dynamic]", organizer: { id: "[redacted/dynamic]", - name: "Unnamed", + name: "Nameless", email: "[redacted/dynamic]", timeZone: "[redacted/dynamic]", language: "[redacted/dynamic]", diff --git a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts index 1289185fa1..1bce932749 100644 --- a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts @@ -51,8 +51,6 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { platformClientParams, } = input; - const tOrganizer = await getTranslation(user.locale ?? "en", "common"); - const booking = await prisma.booking.findUniqueOrThrow({ where: { id: bookingId, @@ -110,6 +108,18 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { }, location: true, userId: true, + user: { + select: { + id: true, + username: true, + email: true, + timeZone: true, + timeFormat: true, + name: true, + destinationCalendar: true, + locale: true, + }, + }, id: true, uid: true, payment: true, @@ -183,6 +193,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { ); const attendeesList = await Promise.all(attendeesListPromises); + const tOrganizer = await getTranslation(booking.user?.locale ?? "en", "common"); const evt: CalendarEvent = { type: booking?.eventType?.slug as string, @@ -198,20 +209,20 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { startTime: booking.startTime.toISOString(), endTime: booking.endTime.toISOString(), organizer: { - email: booking.userPrimaryEmail ?? user.email, - name: user.name || "Unnamed", - username: user.username || undefined, - timeZone: user.timeZone, - timeFormat: getTimeFormatStringFromUserTimeFormat(user.timeFormat), - language: { translate: tOrganizer, locale: user.locale ?? "en" }, + email: booking?.userPrimaryEmail || booking.user?.email || "Email-less", + name: booking.user?.name || "Nameless", + username: booking.user?.username || undefined, + timeZone: booking.user?.timeZone || "Europe/London", + timeFormat: getTimeFormatStringFromUserTimeFormat(booking.user?.timeFormat), + language: { translate: tOrganizer, locale: booking.user?.locale ?? "en" }, }, attendees: attendeesList, location: booking.location ?? "", uid: booking.uid, - destinationCalendar: booking?.destinationCalendar + destinationCalendar: booking.destinationCalendar ? [booking.destinationCalendar] - : user.destinationCalendar - ? [user.destinationCalendar] + : booking.user?.destinationCalendar + ? [booking.user?.destinationCalendar] : [], requiresConfirmation: booking?.eventType?.requiresConfirmation ?? false, eventTypeId: booking.eventType?.id,