From 4f63ba1a950ded0f768033a2c2370cca53891013 Mon Sep 17 00:00:00 2001 From: Hariom Date: Sat, 31 Aug 2024 13:24:16 +0530 Subject: [PATCH] Fix unconfirmed bookings blocking slots being fetched for all troubleshooters --- packages/core/getBusyTimes.ts | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/core/getBusyTimes.ts b/packages/core/getBusyTimes.ts index 263ff90252d0f6..a4f479a76694e2 100644 --- a/packages/core/getBusyTimes.ts +++ b/packages/core/getBusyTimes.ts @@ -155,29 +155,31 @@ export async function getBusyTimes(params: { select: bookingsSelect, }); - const currentBookingsAllUsersQueryThree = prisma.booking.findMany({ - where: { - startTime: { lte: endTimeDate }, - endTime: { gte: startTimeDate }, - eventType: { - id: eventTypeId, - requiresConfirmation: true, - requiresConfirmationWillBlockSlot: true, - }, - status: { - in: [BookingStatus.PENDING], - }, - }, - select: bookingsSelect, - }); + const unconfirmedBookingsBlockingSlots = eventTypeId + ? prisma.booking.findMany({ + where: { + startTime: { lte: endTimeDate }, + endTime: { gte: startTimeDate }, + eventType: { + id: eventTypeId, + requiresConfirmation: true, + requiresConfirmationWillBlockSlot: true, + }, + status: { + in: [BookingStatus.PENDING], + }, + }, + select: bookingsSelect, + }) + : null; const [resultOne, resultTwo, resultThree] = await Promise.all([ currentBookingsAllUsersQueryOne, currentBookingsAllUsersQueryTwo, - currentBookingsAllUsersQueryThree, + unconfirmedBookingsBlockingSlots, ]); - bookings = [...resultOne, ...resultTwo, ...resultThree]; + bookings = [...resultOne, ...resultTwo, ...(resultThree ?? [])]; } const bookingSeatCountMap: { [x: string]: number } = {};