Buffer limits fix#5248
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| end: dayjs(a.end) | ||
| .add(currentUser.bufferTime + (afterEventBuffer || 0), "minute") | ||
| start: dayjs(a.start) | ||
| .subtract(afterEventBuffer || 0, "minutes") |
There was a problem hiding this comment.
I will investigate this on Monday :) Although this is different behaviour from what myself and @Jaibles have experienced.
There was a problem hiding this comment.
Confirmed this is indeed a bug @CarinaWolli - nice spot. It happens when you book 2:30 before you book 2:15. beforeBuffer needs to be taken into account in the busyTime
Yea the conversation was largely about ensuring you cannot end up with back to back meetings (and preventing it actually requires adding a buffer before and after even if you've just set before) |
|
Pretty sure in this logic we can still end up with back to back bookings by simply booking through an event type which doesn't have buffer. @sean-brydon @Jaibles |
CarinaWolli
left a comment
There was a problem hiding this comment.
I left you one comment. However, I found another bug that has nothing to do with your PR that makes it unable to even test this. I tried to book 2 different event types (one has only a before buffer and one has before and after), but I realized that busyTimes only includes the bookings from the event type that is currently booked. I think we need to remove the eventTypeId when querying the busyTimes, so we also include all other bookings from different event types in the availabilities
| bookings.map(({ startTime, endTime, title, id, eventType }) => ({ | ||
| start: startTime, | ||
| end: dayjs(endTime) | ||
| .add((eventType?.afterEventBuffer || afterEventBuffer || 0) + (beforeEventBuffer || 0), "minute") |
There was a problem hiding this comment.
I think we only need to add eventType.afterEventBuffer here. If there is none, we don't need to add the afterEventBuffer from the booking.
| .findMany({ | ||
| where: { | ||
| userId, | ||
| eventTypeId, |
There was a problem hiding this comment.
Nice spot @CarinaWolli - Looks like we were only getting busy events for this particular event type and not all event types. Potentially allowing a double booking (same time) as each other
|
|
||
| MockDate.set("2021-06-20T11:59:59Z"); | ||
|
|
||
| it("can fit 24 hourly slots for an empty day", async () => { |
There was a problem hiding this comment.
Remove tests on code that isn't used in product anymore
| start: startTime, | ||
| bookings.map(({ startTime, endTime, title, id, eventType }) => ({ | ||
| start: dayjs(startTime) | ||
| .subtract((eventType?.beforeEventBuffer || 0) + (afterEventBuffer || 0), "minute") |
There was a problem hiding this comment.
Thanks @CarinaWolli for this fix :)
Always subtract the beforeEventBuffer for this specific booking eventType - then add afterEventBuffer for the buffer you are trying to book.
Preventing different event types from having a clash
| busyTimes.push( | ||
| ...calendarBusyTimes.map((value) => ({ | ||
| ...value, | ||
| end: dayjs(value.end) |
There was a problem hiding this comment.
Always add beforeEventBuffer to the end time so we get separation on calendar events
Without this we could book a meeting straight after a normal calendar event.
| .add(beforeEventBuffer || 0, "minute") | ||
| .toDate(), | ||
| start: dayjs(value.start) | ||
| .subtract(afterEventBuffer || 0, "minute") |
There was a problem hiding this comment.
Always subtract afterEventBuffer if it exists
| const bufferedBusyTimes: EventBusyDetails[] = busyTimes.map((a) => ({ | ||
| ...a, | ||
| start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toISOString(), | ||
| end: dayjs(a.end) |
There was a problem hiding this comment.
This logic is handled in getBusyTimes now as bookings/calendar events require different logic
| currentSeats, | ||
| }: { | ||
| time: Dayjs; | ||
| busy: (TimeRange | { start: string; end: string } | EventBusyDate)[]; |
There was a problem hiding this comment.
These types just simply are EventBusyDate - not sure why we replicated this
|
|
||
| return busy.every((busyTime) => { | ||
| const startTime = dayjs.utc(busyTime.start).subtract(beforeBufferTime, "minutes").utc(); | ||
| const startTime = dayjs.utc(busyTime.start).utc(); |
There was a problem hiding this comment.
Handled in getBusyTimes
alishaz-polymath
left a comment
There was a problem hiding this comment.
Looks good to me. Buffer specific testing went well
Awesome job @sean-brydon
CarinaWolli
left a comment
There was a problem hiding this comment.
Tested and works as expected 👏🏻
* Buffer limits + remove redundant tests * Fixing buffer * Compound * Afterbuffer fix for no event afterbuffer set * Bug fixes * Buffer includes eventType before


This PR fixes the buffer limit logic for before + after limits.
I will record a Loom for this tomorrow if needed. Please checkout and test this branch on preview to ensure the correct behaviour is indented.