Skip to content

Commit

Permalink
chore: Add more logging around getUserAvailability (#18769)
Browse files Browse the repository at this point in the history
* chore: Add more logging around getUserAvailability

* Add initialData to logging
  • Loading branch information
emrysal authored Jan 20, 2025
1 parent 1a64915 commit 01baf7d
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions packages/core/getUserAvailability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
shouldServeCache,
} = availabilitySchema.parse(query);

log.debug(
`[getUserAvailability] EventType: ${eventTypeId} | User: ${username} (ID: ${userId}) - Called with: ${safeStringify(
{
query,
initialData,
}
)}`
);

if (!dateFrom.isValid() || !dateTo.isValid()) {
throw new HttpError({ statusCode: 400, message: "Invalid time range given." });
}
Expand All @@ -296,11 +305,9 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA

const user = initialData?.user || (await getUser(where));

if (!user) throw new HttpError({ statusCode: 404, message: "No user found in getUserAvailability" });
log.debug(
"getUserAvailability for user",
safeStringify({ user: { id: user.id }, slot: { dateFrom, dateTo } })
);
if (!user) {
throw new HttpError({ statusCode: 404, message: "No user found in getUserAvailability" });
}

let eventType: EventType | null = initialData?.eventType || null;
if (!eventType && eventTypeId) eventType = await getEventType(eventTypeId);
Expand Down Expand Up @@ -420,13 +427,14 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
const isDefaultSchedule = userSchedule && userSchedule.id === schedule?.id;

log.debug(
"Using schedule:",
safeStringify({
chosenSchedule: schedule,
eventTypeSchedule: eventType?.schedule,
userSchedule: userSchedule,
hostSchedule: hostSchedule,
})
`[getUserAvailability] EventType: ${eventTypeId} | User: ${username} (ID: ${userId}) - usingSchedule: ${safeStringify(
{
chosenSchedule: schedule,
eventTypeSchedule: eventType?.schedule,
userSchedule: userSchedule,
hostSchedule: hostSchedule,
}
)}`
);

if (
Expand Down Expand Up @@ -566,7 +574,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
const dateRangesInWhichUserIsAvailable = subtract(dateRanges, formattedBusyTimes);
const dateRangesInWhichUserIsAvailableWithoutOOO = subtract(oooExcludedDateRanges, formattedBusyTimes);

return {
const result = {
busy: detailedBusyTimes,
timeZone,
dateRanges: dateRangesInWhichUserIsAvailable,
Expand All @@ -576,6 +584,14 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
currentSeats,
datesOutOfOffice,
};

log.debug(
`[getUserAvailability] EventType: ${eventTypeId} | User: ${username} (ID: ${userId}) - Result: ${safeStringify(
result
)}`
);

return result;
};

export const getPeriodStartDatesBetween = (
Expand Down

0 comments on commit 01baf7d

Please sign in to comment.