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:
33 files changed
+673
-84
No files matched your search
@@ -33,6 +33,7 @@ export const getScheduleSchemaObject = z.object({
|
||||
teamMemberEmail: z.string().nullish(),
|
||||
routedTeamMemberIds: z.array(z.number()).nullish(),
|
||||
skipContactOwner: z.boolean().nullish(),
|
||||
rrHostSubsetIds: z.array(z.number()).nullish(),
|
||||
_enableTroubleshooter: z.boolean().optional(),
|
||||
_bypassCalendarBusyTimes: z.boolean().optional(),
|
||||
_silentCalendarFailures: z.boolean().optional(),
|
||||
|
||||
@@ -28,6 +28,7 @@ import type { IRedisService } from "@calcom/features/redis/IRedisService";
|
||||
import { buildDateRanges } from "@calcom/features/schedules/lib/date-ranges";
|
||||
import getSlots from "@calcom/features/schedules/lib/slots";
|
||||
import type { ScheduleRepository } from "@calcom/features/schedules/repositories/ScheduleRepository";
|
||||
import type { NoSlotsNotificationService } from "@calcom/features/slots/handleNotificationWhenNoSlots";
|
||||
import type { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { withSelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
|
||||
@@ -58,7 +59,6 @@ import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TGetScheduleInputSchema } from "./getSchedule.schema";
|
||||
import type { NoSlotsNotificationService } from "@calcom/features/slots/handleNotificationWhenNoSlots";
|
||||
import type { GetScheduleOptions } from "./types";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[slots/util]"] });
|
||||
@@ -148,7 +148,7 @@ function withSlotsCache(
|
||||
}
|
||||
|
||||
export class AvailableSlotsService {
|
||||
constructor(public readonly dependencies: IAvailableSlotsService) { }
|
||||
constructor(public readonly dependencies: IAvailableSlotsService) {}
|
||||
|
||||
private async _getReservedSlotsAndCleanupExpired({
|
||||
bookerClientUid,
|
||||
@@ -199,8 +199,8 @@ export class AvailableSlotsService {
|
||||
usernameList: Array.isArray(input.usernameList)
|
||||
? input.usernameList
|
||||
: input.usernameList
|
||||
? [input.usernameList]
|
||||
: [],
|
||||
? [input.usernameList]
|
||||
: [],
|
||||
});
|
||||
|
||||
const usersWithOldSelectedCalendars = usersForDynamicEventType.map((user) => withSelectedCalendars(user));
|
||||
@@ -790,15 +790,15 @@ export class AvailableSlotsService {
|
||||
|
||||
const bookingLimits =
|
||||
eventType?.bookingLimits &&
|
||||
typeof eventType?.bookingLimits === "object" &&
|
||||
Object.keys(eventType?.bookingLimits).length > 0
|
||||
typeof eventType?.bookingLimits === "object" &&
|
||||
Object.keys(eventType?.bookingLimits).length > 0
|
||||
? parseBookingLimit(eventType?.bookingLimits)
|
||||
: null;
|
||||
|
||||
const durationLimits =
|
||||
eventType?.durationLimits &&
|
||||
typeof eventType?.durationLimits === "object" &&
|
||||
Object.keys(eventType?.durationLimits).length > 0
|
||||
typeof eventType?.durationLimits === "object" &&
|
||||
Object.keys(eventType?.durationLimits).length > 0
|
||||
? parseDurationLimit(eventType?.durationLimits)
|
||||
: null;
|
||||
|
||||
@@ -966,9 +966,9 @@ export class AvailableSlotsService {
|
||||
} = input;
|
||||
const orgDetails = input?.orgSlug
|
||||
? {
|
||||
currentOrgDomain: input.orgSlug,
|
||||
isValidOrgDomain: !!input.orgSlug && !RESERVED_SUBDOMAINS.includes(input.orgSlug),
|
||||
}
|
||||
currentOrgDomain: input.orgSlug,
|
||||
isValidOrgDomain: !!input.orgSlug && !RESERVED_SUBDOMAINS.includes(input.orgSlug),
|
||||
}
|
||||
: orgDomainConfig(ctx?.req);
|
||||
|
||||
if (process.env.INTEGRATION_TEST_MODE === "true") {
|
||||
@@ -981,7 +981,7 @@ export class AvailableSlotsService {
|
||||
throw new TRPCError({ code: "NOT_FOUND" });
|
||||
}
|
||||
|
||||
const shouldServeCache = false
|
||||
const shouldServeCache = false;
|
||||
if (isEventTypeLoggingEnabled({ eventTypeId: eventType.id })) {
|
||||
logger.settings.minLevel = 2;
|
||||
}
|
||||
@@ -1042,6 +1042,7 @@ export class AvailableSlotsService {
|
||||
routedTeamMemberIds,
|
||||
contactOwnerEmail,
|
||||
routingFormResponse,
|
||||
rrHostSubsetIds: input.rrHostSubsetIds ?? undefined,
|
||||
});
|
||||
|
||||
const allHosts = [...qualifiedRRHosts, ...fixedHosts];
|
||||
@@ -1184,10 +1185,10 @@ export class AvailableSlotsService {
|
||||
const travelSchedules =
|
||||
isDefaultSchedule && !eventType.useBookerTimezone
|
||||
? restrictionSchedule.user.travelSchedules.map((schedule) => ({
|
||||
startDate: dayjs(schedule.startDate),
|
||||
endDate: schedule.endDate ? dayjs(schedule.endDate) : undefined,
|
||||
timeZone: schedule.timeZone,
|
||||
}))
|
||||
startDate: dayjs(schedule.startDate),
|
||||
endDate: schedule.endDate ? dayjs(schedule.endDate) : undefined,
|
||||
timeZone: schedule.timeZone,
|
||||
}))
|
||||
: [];
|
||||
|
||||
const { dateRanges: restrictionRanges } = buildDateRanges({
|
||||
@@ -1282,9 +1283,9 @@ export class AvailableSlotsService {
|
||||
(
|
||||
item:
|
||||
| {
|
||||
time: dayjs.Dayjs;
|
||||
userIds?: number[] | undefined;
|
||||
}
|
||||
time: dayjs.Dayjs;
|
||||
userIds?: number[] | undefined;
|
||||
}
|
||||
| undefined
|
||||
): item is {
|
||||
time: dayjs.Dayjs;
|
||||
@@ -1453,23 +1454,23 @@ export class AvailableSlotsService {
|
||||
|
||||
const troubleshooterData = enableTroubleshooter
|
||||
? {
|
||||
troubleshooter: {
|
||||
routedTeamMemberIds: routedTeamMemberIds,
|
||||
// One that Salesforce asked for
|
||||
askedContactOwner: contactOwnerEmailFromInput,
|
||||
// One that we used as per Routing skipContactOwner flag
|
||||
consideredContactOwner: contactOwnerEmail,
|
||||
// All hosts that have been checked for availability. If no routedTeamMemberIds are provided, this will be same as hosts.
|
||||
routedHosts: usersWithCredentials.map((user) => {
|
||||
return {
|
||||
userId: user.id,
|
||||
};
|
||||
}),
|
||||
hostsAfterSegmentMatching: allHosts.map((host) => ({
|
||||
userId: host.user.id,
|
||||
})),
|
||||
},
|
||||
}
|
||||
troubleshooter: {
|
||||
routedTeamMemberIds: routedTeamMemberIds,
|
||||
// One that Salesforce asked for
|
||||
askedContactOwner: contactOwnerEmailFromInput,
|
||||
// One that we used as per Routing skipContactOwner flag
|
||||
consideredContactOwner: contactOwnerEmail,
|
||||
// All hosts that have been checked for availability. If no routedTeamMemberIds are provided, this will be same as hosts.
|
||||
routedHosts: usersWithCredentials.map((user) => {
|
||||
return {
|
||||
userId: user.id,
|
||||
};
|
||||
}),
|
||||
hostsAfterSegmentMatching: allHosts.map((host) => ({
|
||||
userId: host.user.id,
|
||||
})),
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user