From b7e11dc112b360a475e27361fd4d51f95eab371e Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Sat, 2 Aug 2025 12:15:30 -0400 Subject: [PATCH] chore: Add logging to handleNewBooking (#22868) * Add logging * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update logger config, fix Create booking log * Added oooExcludedDateRanges + type error fix --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Alex van Andel --- .../features/bookings/lib/handleNewBooking.ts | 22 ++++++++++++++++++- packages/lib/getBusyTimes.ts | 4 ++++ packages/lib/logger.ts | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index ebe8d1ec24..1431047694 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -387,6 +387,23 @@ export type BookingHandlerInput = { forcedSlug?: string; } & PlatformParams; +function formatAvailabilitySnapshot(data: { + dateRanges: { start: dayjs.Dayjs; end: dayjs.Dayjs }[]; + oooExcludedDateRanges: { start: dayjs.Dayjs; end: dayjs.Dayjs }[]; +}) { + return { + ...data, + dateRanges: data.dateRanges.map(({ start, end }) => ({ + start: start.toISOString(), + end: end.toISOString(), + })), + oooExcludedDateRanges: data.oooExcludedDateRanges.map(({ start, end }) => ({ + start: start.toISOString(), + end: end.toISOString(), + })), + }; +} + async function handler( input: BookingHandlerInput, bookingDataSchemaGetter: BookingDataSchemaGetter = getBookingDataSchema @@ -1397,7 +1414,10 @@ async function handler( logger.info(`Booking created`, { bookingUid: booking.uid, - availabilitySnapshot: organizerUserAvailability?.availabilityData, + selectedCalendarIds: organizerUser.allSelectedCalendars?.map((c) => c.id) ?? [], + availabilitySnapshot: organizerUserAvailability?.availabilityData + ? formatAvailabilitySnapshot(organizerUserAvailability.availabilityData) + : null, }); } diff --git a/packages/lib/getBusyTimes.ts b/packages/lib/getBusyTimes.ts index ee8131027d..2b316d51e5 100644 --- a/packages/lib/getBusyTimes.ts +++ b/packages/lib/getBusyTimes.ts @@ -252,6 +252,10 @@ const _getBusyTimes = async (params: { console.log("videoBusyTimes", videoBusyTimes); busyTimes.push(...videoBusyTimes); */ + } else { + logger.warn(`No credentials found for user ${userId}`, { + selectedCalendarIds: selectedCalendars.map((calendar) => calendar.id), + }); } logger.debug( "getBusyTimes:", diff --git a/packages/lib/logger.ts b/packages/lib/logger.ts index d9f22f3a45..5d60e8dd78 100644 --- a/packages/lib/logger.ts +++ b/packages/lib/logger.ts @@ -9,11 +9,12 @@ const logger = new Logger({ prettyErrorStackTemplate: " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}", // default prettyErrorTemplate: "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}", // default prettyLogTemplate: "{{hh}}:{{MM}}:{{ss}}:{{ms}} [{{logLevelName}}] ", // default with exclusion of `{{filePathWithLine}}` - stylePrettyLogs: true, + stylePrettyLogs: !IS_PRODUCTION, prettyLogStyles: { name: "yellow", dateIsoStr: "blue", }, + type: IS_PRODUCTION ? "json" : "pretty", }); export default logger;