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
@@ -28,6 +28,7 @@ export const bookingCreateBodySchema = z.object({
|
||||
routedTeamMemberIds: z.array(z.number()).nullish(),
|
||||
routingFormResponseId: z.number().optional(),
|
||||
skipContactOwner: z.boolean().optional(),
|
||||
rrHostSubsetIds: z.array(z.number()).nullish(),
|
||||
crmAppSlug: z.string().nullish().optional(),
|
||||
cfToken: z.string().nullish().optional(),
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ const getEventTypesFromDBSelect = {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
rrHostSubsetEnabled: true,
|
||||
instantMeetingExpiryTimeOffsetInSeconds: true,
|
||||
autoTranslateInstantMeetingTitleEnabled: true,
|
||||
} satisfies Prisma.EventTypeSelect;
|
||||
|
||||
@@ -53,6 +53,7 @@ type EventType = Pick<
|
||||
| "rescheduleWithSameRoundRobinHost"
|
||||
| "teamId"
|
||||
| "includeNoShowInRRCalculation"
|
||||
| "rrHostSubsetEnabled"
|
||||
>;
|
||||
|
||||
type InputProps = {
|
||||
@@ -67,6 +68,7 @@ type InputProps = {
|
||||
isPlatform: boolean;
|
||||
hostname: string | undefined;
|
||||
forcedSlug: string | undefined;
|
||||
rrHostSubsetIds?: number[];
|
||||
};
|
||||
|
||||
const _loadAndValidateUsers = async ({
|
||||
@@ -81,6 +83,7 @@ const _loadAndValidateUsers = async ({
|
||||
isPlatform,
|
||||
hostname,
|
||||
forcedSlug,
|
||||
rrHostSubsetIds,
|
||||
}: InputProps): Promise<{
|
||||
qualifiedRRUsers: UsersWithDelegationCredentials;
|
||||
additionalFallbackRRUsers: UsersWithDelegationCredentials;
|
||||
@@ -155,6 +158,7 @@ const _loadAndValidateUsers = async ({
|
||||
rescheduleUid,
|
||||
contactOwnerEmail,
|
||||
routingFormResponse,
|
||||
rrHostSubsetIds,
|
||||
});
|
||||
const allQualifiedHostsHashMap = [...qualifiedRRHosts, ...(allFallbackRRHosts ?? []), ...fixedHosts].reduce(
|
||||
(acc, host) => {
|
||||
|
||||
+33
-3
@@ -7,7 +7,7 @@ import {
|
||||
import type { EventType } from "@calcom/features/users/lib/getRoutedUsers";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { CredentialForCalendarService, CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
import { filterHostsByLeadThreshold } from "./filterHostsByLeadThreshold";
|
||||
@@ -54,6 +54,23 @@ const isFixedHost = <T extends { isFixed: boolean }>(host: T): host is T & { isF
|
||||
return host.isFixed;
|
||||
};
|
||||
|
||||
const isWithinRRHostSubset = <T extends { isFixed: boolean; user: { id: number } }>(
|
||||
host: T,
|
||||
rrHostSubsetIds: number[],
|
||||
{
|
||||
rrHostSubsetEnabled,
|
||||
schedulingType,
|
||||
}: { rrHostSubsetEnabled: boolean; schedulingType?: SchedulingType } = {
|
||||
rrHostSubsetEnabled: false,
|
||||
schedulingType: undefined,
|
||||
}
|
||||
): host is T & { isFixed: false } => {
|
||||
if (rrHostSubsetIds.length === 0 || !rrHostSubsetEnabled || schedulingType !== SchedulingType.ROUND_ROBIN) {
|
||||
return true;
|
||||
}
|
||||
return rrHostSubsetIds.includes(host.user.id);
|
||||
};
|
||||
|
||||
export class QualifiedHostsService {
|
||||
constructor(public readonly dependencies: IQualifiedHostsService) {}
|
||||
|
||||
@@ -70,6 +87,7 @@ export class QualifiedHostsService {
|
||||
routedTeamMemberIds,
|
||||
contactOwnerEmail,
|
||||
routingFormResponse,
|
||||
rrHostSubsetIds,
|
||||
}: {
|
||||
eventType: {
|
||||
id: number;
|
||||
@@ -80,11 +98,13 @@ export class QualifiedHostsService {
|
||||
isRRWeightsEnabled: boolean;
|
||||
rescheduleWithSameRoundRobinHost: boolean;
|
||||
includeNoShowInRRCalculation: boolean;
|
||||
rrHostSubsetEnabled?: boolean;
|
||||
} & EventType;
|
||||
rescheduleUid: string | null;
|
||||
routedTeamMemberIds: number[];
|
||||
contactOwnerEmail: string | null;
|
||||
routingFormResponse: RoutingFormResponse | null;
|
||||
rrHostSubsetIds?: number[];
|
||||
}): Promise<{
|
||||
qualifiedRRHosts: {
|
||||
isFixed: boolean;
|
||||
@@ -120,8 +140,18 @@ export class QualifiedHostsService {
|
||||
return { qualifiedRRHosts: roundRobinHosts, fixedHosts };
|
||||
}
|
||||
|
||||
const fixedHosts = normalizedHosts.filter(isFixedHost);
|
||||
const roundRobinHosts = normalizedHosts.filter(isRoundRobinHost);
|
||||
const fixedHosts = normalizedHosts.filter(isFixedHost).filter((host) =>
|
||||
isWithinRRHostSubset(host, rrHostSubsetIds ?? [], {
|
||||
rrHostSubsetEnabled: eventType.rrHostSubsetEnabled ?? false,
|
||||
schedulingType: eventType.schedulingType ?? undefined,
|
||||
})
|
||||
);
|
||||
const roundRobinHosts = normalizedHosts.filter(isRoundRobinHost).filter((host) =>
|
||||
isWithinRRHostSubset(host, rrHostSubsetIds ?? [], {
|
||||
rrHostSubsetEnabled: eventType.rrHostSubsetEnabled ?? false,
|
||||
schedulingType: eventType.schedulingType ?? undefined,
|
||||
})
|
||||
);
|
||||
|
||||
// If it is rerouting, we should not force reschedule with same host.
|
||||
const hostsAfterRescheduleWithSameRoundRobinHost = applyFilterWithFallback(
|
||||
|
||||
@@ -578,6 +578,7 @@ async function handler(
|
||||
routedTeamMemberIds,
|
||||
reroutingFormResponses,
|
||||
routingFormResponseId,
|
||||
rrHostSubsetIds,
|
||||
_isDryRun: isDryRun = false,
|
||||
...reqBody
|
||||
} = bookingData;
|
||||
@@ -828,6 +829,7 @@ async function handler(
|
||||
contactOwnerEmail,
|
||||
rescheduleUid: reqBody.rescheduleUid || null,
|
||||
routingFormResponse,
|
||||
rrHostSubsetIds: rrHostSubsetIds ?? undefined,
|
||||
});
|
||||
|
||||
// We filter out users but ensure allHostUsers remain same.
|
||||
|
||||
@@ -237,6 +237,7 @@ export default async function handleChildrenEventTypes({
|
||||
useBookerTimezone: false,
|
||||
allowReschedulingCancelledBookings:
|
||||
managedEventTypeValues.allowReschedulingCancelledBookings ?? false,
|
||||
rrHostSubsetEnabled: false,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -331,6 +332,7 @@ export default async function handleChildrenEventTypes({
|
||||
},
|
||||
data: {
|
||||
...updatePayloadFiltered,
|
||||
rrHostSubsetEnabled: false,
|
||||
hidden: children?.find((ch) => ch.owner.id === userId)?.hidden ?? false,
|
||||
...("schedule" in unlockedFieldProps ? {} : { scheduleId: eventType.scheduleId || null }),
|
||||
restrictionScheduleId: null,
|
||||
|
||||
@@ -153,6 +153,7 @@ const commons = {
|
||||
bookingRequiresAuthentication: false,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
rrHostSubsetEnabled: false,
|
||||
};
|
||||
|
||||
export const dynamicEvent = {
|
||||
|
||||
@@ -2,19 +2,23 @@ import { MembershipRepository } from "@calcom/features/membership/repositories/M
|
||||
import { LookupTarget, ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
|
||||
import type { UserWithLegacySelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { withSelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { eventTypeSelect } from "@calcom/lib/server/eventTypeSelect";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { prisma, availabilityUserSelect, userSelect as userSelectWithSelectedCalendars } from "@calcom/prisma";
|
||||
import {
|
||||
prisma,
|
||||
availabilityUserSelect,
|
||||
userSelect as userSelectWithSelectedCalendars,
|
||||
} from "@calcom/prisma";
|
||||
import type { EventType as PrismaEventType } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import { EventTypeMetaDataSchema, rrSegmentQueryValueSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { Ensure } from "@calcom/types/utils";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["repository/eventType"] });
|
||||
|
||||
@@ -1272,6 +1276,7 @@ export class EventTypeRepository {
|
||||
useEventLevelSelectedCalendars: true,
|
||||
restrictionScheduleId: true,
|
||||
useBookerTimezone: true,
|
||||
rrHostSubsetEnabled: true,
|
||||
hostGroups: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1590,7 +1595,7 @@ export class EventTypeRepository {
|
||||
return { eventTypes, total };
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* List child event types for a given parent.
|
||||
* Supports search, user exclusion, cursor pagination.
|
||||
*/
|
||||
@@ -1611,14 +1616,16 @@ export class EventTypeRepository {
|
||||
const eventTypeWhere = {
|
||||
parentId: parentEventTypeId,
|
||||
...(excludeUserId ? { userId: { not: excludeUserId } } : {}),
|
||||
...(searchTerm ? {
|
||||
owner: {
|
||||
OR: [
|
||||
{ name: { contains: searchTerm, mode: "insensitive" as const } },
|
||||
{ email: { contains: searchTerm, mode: "insensitive" as const } },
|
||||
],
|
||||
},
|
||||
} : {}),
|
||||
...(searchTerm
|
||||
? {
|
||||
owner: {
|
||||
OR: [
|
||||
{ name: { contains: searchTerm, mode: "insensitive" as const } },
|
||||
{ email: { contains: searchTerm, mode: "insensitive" as const } },
|
||||
],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
|
||||
// Extract query to preserve type inference
|
||||
@@ -1636,9 +1643,9 @@ export class EventTypeRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
take: limit + 1, // over-fetch for nextCursor
|
||||
take: limit + 1, // over-fetch for nextCursor
|
||||
...(cursor && { skip: 1, cursor: { id: cursor } }),
|
||||
orderBy: { id: "asc" }, // deterministic pagination
|
||||
orderBy: { id: "asc" }, // deterministic pagination
|
||||
});
|
||||
|
||||
const [totalCount, rows] = await Promise.all([
|
||||
@@ -1657,20 +1664,20 @@ export class EventTypeRepository {
|
||||
};
|
||||
}
|
||||
|
||||
async findByIdWithParentAndUserId(eventTypeId: number) {
|
||||
return this.prismaClient.eventType.findUnique({
|
||||
where: { id: eventTypeId },
|
||||
select: {
|
||||
id: true,
|
||||
parentId: true,
|
||||
userId: true,
|
||||
schedulingType: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async findByIdWithParentAndUserId(eventTypeId: number) {
|
||||
return this.prismaClient.eventType.findUnique({
|
||||
where: { id: eventTypeId },
|
||||
select: {
|
||||
id: true,
|
||||
parentId: true,
|
||||
userId: true,
|
||||
schedulingType: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByIdTargetChildEventType(userId: number, parentId: number) {
|
||||
return this.prismaClient.eventType.findUnique({
|
||||
async findByIdTargetChildEventType(userId: number, parentId: number) {
|
||||
return this.prismaClient.eventType.findUnique({
|
||||
where: {
|
||||
userId_parentId: {
|
||||
userId,
|
||||
|
||||
@@ -165,6 +165,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
|
||||
bookingRequiresAuthentication: false,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
rrHostSubsetEnabled: false,
|
||||
...eventType,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+10
@@ -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;
|
||||
}
|
||||
+15
-1
@@ -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;
|
||||
}
|
||||
+10
@@ -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";
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "public"."EventType" ADD COLUMN "rrHostSubsetEnabled" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -256,6 +256,7 @@ model EventType {
|
||||
hostGroups HostGroup[]
|
||||
|
||||
bookingRequiresAuthentication Boolean @default(false)
|
||||
rrHostSubsetEnabled Boolean @default(false)
|
||||
|
||||
createdAt DateTime? @default(now())
|
||||
updatedAt DateTime? @updatedAt
|
||||
|
||||
@@ -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