From 7fde30edf91052c8f9748a65b17eaac2b01e2361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efra=C3=ADn=20Roch=C3=ADn?= Date: Thu, 13 Apr 2023 11:26:45 -0700 Subject: [PATCH] avoid get error when a user has no schedule defined in getUserAvailability function (#8170) --- packages/core/getUserAvailability.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts index a5a8fdc427..942ec1b26a 100644 --- a/packages/core/getUserAvailability.ts +++ b/packages/core/getUserAvailability.ts @@ -119,8 +119,9 @@ export async function getUserAvailability( const { username, userId, dateFrom, dateTo, eventTypeId, afterEventBuffer, beforeEventBuffer, duration } = availabilitySchema.parse(query); - if (!dateFrom.isValid() || !dateTo.isValid()) + if (!dateFrom.isValid() || !dateTo.isValid()) { throw new HttpError({ statusCode: 400, message: "Invalid time range given." }); + } const where: Prisma.UserWhereUniqueInput = {}; if (username) where.username = username; @@ -196,7 +197,7 @@ export async function getUserAvailability( const startGetWorkingHours = performance.now(); - const timeZone = schedule.timeZone || eventType?.timeZone || user.timeZone; + const timeZone = schedule?.timeZone || eventType?.timeZone || user.timeZone; const availability = ( schedule.availability || (eventType?.availability.length ? eventType.availability : user.availability)