avoid get error when a user has no schedule defined in getUserAvailability function (#8170)

This commit is contained in:
Efraín Rochín 2023-04-13 11:26:45 -07:00 committed by GitHub
parent 0e22e92cab
commit 7fde30edf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)