feat: add hostSubsetIds parameter for round robin host filtering (#25627)

* feat: add hostSubsetIds parameter for round robin host filtering

Add support for filtering round robin event type hosts via API v2.
When hostSubsetIds is provided, only the specified hosts are considered
for availability calculation and booking assignment.

Changes:
- Add hostSubsetIds to slots API input (GET /slots/available)
- Add hostSubsetIds to booking API input (POST /bookings)
- Update _findQualifiedHostsWithDelegationCredentials to filter by hostSubsetIds
- Pass hostSubsetIds through all layers: API -> tRPC -> slots/booking services

This allows API consumers to request availability and create bookings
for a subset of hosts within a round robin event type.

Co-Authored-By: [email protected] <[email protected]>

* chore: add e2e tests

* chore: add enableHostSubset team event-type setting

* fixup! chore: add enableHostSubset team event-type setting

* fix tests

* fix tests

* improve isWithinRRHostSubset

* rename to rrHost subset

* fix ai review

* fix: add booker platform wrapper rrHostSubsetIds prop

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-12-10 10:37:39 +00:00
1 parent 300b9c916d
commit 6b62557a92
33 files changed
+673 -84

No files matched your search

@@ -71,6 +71,7 @@ const BookerPlatformWrapperComponent = (
silentlyHandleCalendarFailures = false,
hideEventMetadata = false,
defaultPhoneCountry,
rrHostSubsetIds,
} = props;
const layout = BookerLayouts[view];
@@ -296,6 +297,7 @@ const BookerPlatformWrapperComponent = (
? {
isTeamEvent: props.isTeamEvent,
teamId: teamId,
rrHostSubsetIds: rrHostSubsetIds,
}
: {}),
enabled:
@@ -444,6 +446,11 @@ const BookerPlatformWrapperComponent = (
locationUrl: props.locationUrl,
routingFormSearchParams,
isBookingDryRun: isBookingDryRun ?? routingParams?.isBookingDryRun,
...(props.isTeamEvent
? {
rrHostSubsetIds: rrHostSubsetIds,
}
: {}),
});
const onOverlaySwitchStateChange = useCallback(
+7 -6
View File
@@ -1,20 +1,20 @@
import type React from "react";
import type { BookerProps } from "@calcom/features/bookings/Booker";
import type { BookerStore, CountryCode } from "@calcom/features/bookings/Booker/store";
import type { Timezone, VIEW_TYPE } from "@calcom/features/bookings/Booker/types";
import type { BookingCreateBody } from "@calcom/features/bookings/lib/bookingCreateBodySchema";
import type { BookingResponse } from "@calcom/platform-libraries";
import type { ApiSuccessResponse, ApiErrorResponse, ApiSuccessResponseWithoutData, RoutingFormSearchParams } from "@calcom/platform-types";
import type {
ApiSuccessResponse,
ApiErrorResponse,
ApiSuccessResponseWithoutData,
RoutingFormSearchParams,
} from "@calcom/platform-types";
import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types";
import type { UseCreateBookingInput } from "../hooks/bookings/useCreateBooking";
// Type that includes only the data values from BookerStore (excluding functions)
export type BookerStoreValues = Omit<
BookerStore,
@@ -102,4 +102,5 @@ export type BookerPlatformWrapperAtomPropsForTeam = BookerPlatformWrapperAtomPro
isTeamEvent: true;
teamId: number;
routingFormSearchParams?: RoutingFormSearchParams;
rrHostSubsetIds?: number[];
};
@@ -31,6 +31,7 @@ type UseHandleBookingProps = {
locationUrl?: string;
routingFormSearchParams?: RoutingFormSearchParams;
isBookingDryRun?: boolean;
rrHostSubsetIds?: number[];
};
export const useHandleBookEvent = ({
@@ -44,6 +45,7 @@ export const useHandleBookEvent = ({
locationUrl,
routingFormSearchParams,
isBookingDryRun,
rrHostSubsetIds,
}: UseHandleBookingProps) => {
const isPlatform = useIsPlatform();
const setFormValues = useBookerStoreContext((state) => state.setFormValues);
@@ -115,6 +117,7 @@ export const useHandleBookEvent = ({
routingFormSearchParams,
isDryRunProp: isBookingDryRun,
verificationCode: verificationCode || undefined,
rrHostSubsetIds,
};
const tracking = getUtmTrackingParameters(searchParams);
@@ -29,6 +29,7 @@ export const useAvailableSlots = ({
rest.routedTeamMemberIds,
rest.skipContactOwner,
rest.teamMemberEmail,
rest.rrHostSubsetIds,
],
queryFn: () => {
return http
@@ -1,4 +1,10 @@
import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath } from "@nestjs/swagger";
import {
ApiExtraModels,
ApiHideProperty,
ApiProperty,
ApiPropertyOptional,
getSchemaPath,
} from "@nestjs/swagger";
import { Transform, Type } from "class-transformer";
import type { ValidationArguments, ValidationOptions } from "class-validator";
import {
@@ -388,6 +394,18 @@ export class CreateBookingInput_2024_08_13 {
@IsOptional()
@IsString()
emailVerificationCode?: string;
@ApiPropertyOptional({
type: [Number],
description:
"For round robin event types, filter available hosts to only consider the specified subset of host user IDs. This allows you to book with specific hosts within a round robin event type.",
example: [1, 2, 3],
})
@ApiHideProperty()
@IsOptional()
@IsArray()
@IsInt({ each: true })
rrHostSubsetIds?: number[];
}
export class CreateInstantBookingInput_2024_08_13 extends CreateBookingInput_2024_08_13 {
@@ -3,6 +3,7 @@ import {
ApiPropertyOptional as DocsPropertyOptional,
getSchemaPath,
ApiExtraModels,
ApiHideProperty,
} from "@nestjs/swagger";
import { Type, Transform, Expose } from "class-transformer";
import {
@@ -638,4 +639,13 @@ export class CreateTeamEventTypeInput_2024_06_14 extends BaseCreateEventTypeInpu
description: "Rescheduled events will be assigned to the same host as initially scheduled.",
})
rescheduleWithSameRoundRobinHost?: boolean;
@IsBoolean()
@IsOptional()
@DocsPropertyOptional({
description:
"For round robin event types, enable filtering available hosts to only consider a specified subset of host user IDs. This allows you to book with specific hosts within a round robin event type.",
})
@ApiHideProperty()
rrHostSubsetEnabled?: boolean;
}
@@ -1,4 +1,9 @@
import { ApiPropertyOptional as DocsPropertyOptional, getSchemaPath, ApiExtraModels } from "@nestjs/swagger";
import {
ApiPropertyOptional as DocsPropertyOptional,
getSchemaPath,
ApiExtraModels,
ApiHideProperty,
} from "@nestjs/swagger";
import { Type, Transform } from "class-transformer";
import {
IsString,
@@ -552,4 +557,13 @@ export class UpdateTeamEventTypeInput_2024_06_14 extends BaseUpdateEventTypeInpu
description: "Rescheduled events will be assigned to the same host as initially scheduled.",
})
rescheduleWithSameRoundRobinHost?: boolean;
@IsBoolean()
@IsOptional()
@DocsPropertyOptional({
description:
"For round robin event types, enable filtering available hosts to only consider a specified subset of host user IDs. This allows you to book with specific hosts within a round robin event type.",
})
@ApiHideProperty()
rrHostSubsetEnabled?: boolean;
}
@@ -3,6 +3,7 @@ import {
ApiPropertyOptional,
ApiExtraModels,
getSchemaPath,
ApiHideProperty,
} from "@nestjs/swagger";
import { Type } from "class-transformer";
import {
@@ -550,4 +551,13 @@ export class TeamEventTypeOutput_2024_06_14 extends BaseEventTypeOutput_2024_06_
description: "Rescheduled events will be assigned to the same host as initially scheduled.",
})
rescheduleWithSameRoundRobinHost?: boolean;
@IsBoolean()
@IsOptional()
@ApiPropertyOptional({
description:
"For round robin event types, enable filtering available hosts to only consider a specified subset of host user IDs. This allows you to book with specific hosts within a round robin event type.",
})
@ApiHideProperty()
rrHostSubsetEnabled?: boolean;
}
@@ -205,6 +205,27 @@ export class GetAvailableSlotsInput_2024_04_15 {
@IsOptional()
@ApiHideProperty()
teamId?: number;
@Transform(({ value }) => {
if (typeof value === "string") {
return value.split(",").map((id: string) => parseInt(id.trim(), 10));
}
if (Array.isArray(value)) {
return value.map((id) => (typeof id === "string" ? parseInt(id, 10) : id));
}
return value;
})
@IsArray()
@IsNumber({}, { each: true })
@IsOptional()
@ApiPropertyOptional({
type: [Number],
description:
"For round robin event types, filter available slots to only consider the specified subset of host user IDs. This allows you to get availability for specific hosts within a round robin event type.",
example: [1, 2, 3],
})
@ApiHideProperty()
rrHostSubsetIds?: number[];
}
export class RemoveSelectedSlotInput_2024_04_15 {
@@ -1,4 +1,4 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { ApiHideProperty, ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import {
IsDateString,
@@ -88,6 +88,27 @@ export class GetAvailableSlotsInput_2024_09_04 {
example: "abc123def456",
})
bookingUidToReschedule?: string;
@Transform(({ value }) => {
if (typeof value === "string") {
return value.split(",").map((id: string) => parseInt(id.trim(), 10));
}
if (Array.isArray(value)) {
return value.map((id) => (typeof id === "string" ? parseInt(id, 10) : id));
}
return value;
})
@IsArray()
@IsNumber({}, { each: true })
@IsOptional()
@ApiPropertyOptional({
type: [Number],
description:
"For round robin event types, filter available slots to only consider the specified subset of host user IDs. This allows you to get availability for specific hosts within a round robin event type.",
example: [1, 2, 3],
})
@ApiHideProperty()
rrHostSubsetIds?: number[];
}
export const ById_2024_09_04_type = "byEventTypeId";