Skip to content

Commit 481136c

Browse files
committed
fix(bookings): collective events include all hosts' destination calendars; enforce FixedHostsUnavailableForBooking when any fixed host unavailable
1 parent 00866a3 commit 481136c

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

packages/features/bookings/lib/handleNewBooking.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ export const buildEventForTeamEventType = async ({
330330

331331
const teamMembers = await Promise.all(teamMemberPromises);
332332

333+
// Ensure collective events include destination calendars of all non-organizer hosts
334+
if (schedulingType === "COLLECTIVE") {
335+
for (const user of eventTypeWithUsers?.users ?? []) {
336+
if (user.email !== organizerUser.email && user.destinationCalendar) {
337+
teamDestinationCalendars.push({
338+
...user.destinationCalendar,
339+
externalId: processExternalId(user.destinationCalendar),
340+
});
341+
}
342+
}
343+
}
344+
333345
const updatedEvt = CalendarEventBuilder.fromEvent(evt)
334346
?.withDestinationCalendar([...(evt.destinationCalendar ?? []), ...teamDestinationCalendars])
335347
.build();
@@ -1020,9 +1032,18 @@ async function handler(
10201032
const nonEmptyHostGroups = Object.fromEntries(
10211033
Object.entries(hostGroups).filter(([groupId, hosts]) => hosts.length > 0)
10221034
);
1023-
// Only throw error if there are no available hosts at all (neither fixed nor round-robin)
1024-
if (users.length === 0) {
1025-
throw new Error(ErrorCode.RoundRobinHostsUnavailableForBooking);
1035+
// For collective events, if any required fixed host is missing from availability, fail
1036+
if (eventType.schedulingType === SchedulingType.COLLECTIVE) {
1037+
const numFixedHosts = eventTypeWithUsers.hosts.filter((h) => h.isFixed).length;
1038+
const numAvailableFixedHosts = fixedUserPool.length;
1039+
if (numFixedHosts > 0 && numAvailableFixedHosts < numFixedHosts) {
1040+
throw new Error(ErrorCode.FixedHostsUnavailableForBooking);
1041+
}
1042+
} else {
1043+
// Only throw error if there are no available hosts at all (neither fixed nor round-robin)
1044+
if (users.length === 0) {
1045+
throw new Error(ErrorCode.RoundRobinHostsUnavailableForBooking);
1046+
}
10261047
}
10271048

10281049
// Pushing fixed user before the luckyUser guarantees the (first) fixed user as the organizer.

0 commit comments

Comments
 (0)