fix: round-robin booked out of availability (#12376)
## What does this PR do? Fixes that it can happen that Round Robin host is booked outside of availability. I found and fixed the following two scenarios where this can happen: - when host has a date override - when host is available for only a part the event time (for example, booking time 9:00-11:00 and user is only available between 10:00-11:00) Fixes #10315 Fixes #11690 It also fixes that it can happen that round robin doesn't correctly pick the luck user (least recently booked). This happened when a user was an attendee of a booking before, then we always compared this booking and never the actual last booking of this user. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How should this be tested? #### Booked outside of availability: 1. - Create Round Robin event and assign user1 and user2 as round robin hosts - event duration: 120 minutes - user 1 availability: - Monday to Friday 9:00-17:00 - user2 availability: - Monday to Friday 10:00-17:00 - Book event at a 9:00 slot -> check if i user1 is booked - Book event again at a 9:00 slot -> check if user1 is booked again (user2 is not available at that time) 2. - Change availability of user2 - Mark Monday as unavailable - Add date override on any day this month - Book any Monday this month -> see that user 1 is booked - Again Book any Monday this month -> see that user 1 is booked again #### Wrong lucky user - Book event and add user1's email as the attendee email address - Book several slots where both users should be available, and see that it alternates between user1 and user2 (before it ended up always booking user1) ## Mandatory Tasks - [ ] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.
This commit is contained in:
1 parent
48e7b616b8
commit
270d4f6e82
5 files changed
+126
-5
No files matched your search
@@ -401,6 +401,25 @@ async function ensureAvailableUsers(
|
||||
}
|
||||
|
||||
let foundConflict = false;
|
||||
|
||||
let dateRangeForBooking = false;
|
||||
|
||||
//check if event time is within the date range
|
||||
for (const dateRange of dateRanges) {
|
||||
if (
|
||||
(dayjs.utc(input.dateFrom).isAfter(dateRange.start) ||
|
||||
dayjs.utc(input.dateFrom).isSame(dateRange.start)) &&
|
||||
(dayjs.utc(input.dateTo).isBefore(dateRange.end) || dayjs.utc(input.dateTo).isSame(dateRange.end))
|
||||
) {
|
||||
dateRangeForBooking = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dateRangeForBooking) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
foundConflict = checkForConflicts(bufferedBusyTimes, input.dateFrom, duration);
|
||||
} catch {
|
||||
|
||||
@@ -77,6 +77,7 @@ async function leastRecentlyBookedUser<T extends Pick<User, "id" | "email">>({
|
||||
if (aggregate[user.id]) return; // Bookings are ordered DESC, so if the reducer aggregate
|
||||
// contains the user id, it's already got the most recent booking marked.
|
||||
if (!booking.attendees.map((attendee) => attendee.email).includes(user.email)) return;
|
||||
if (organizerIdAndAtCreatedPair[user.id] > booking.createdAt) return; // only consider bookings if they were created after organizer bookings
|
||||
aggregate[user.id] = booking.createdAt;
|
||||
});
|
||||
return aggregate;
|
||||
|
||||
Reference in new issue
Block a user