Revert "refactor: GetAvailableSlotsService (#22321)" (#22334)

This commit is contained in:
Benny Joo
2025-07-08 14:28:59 -07:00
committed by GitHub
parent c3dab3e4f8
commit 02321c33b2
18 changed files with 1271 additions and 1331 deletions
+2 -6
View File
@@ -8,7 +8,7 @@ import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
import { createContext } from "@calcom/trpc/server/createContext";
import { getScheduleSchema } from "@calcom/trpc/server/routers/viewer/slots/types";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
import { TRPCError } from "@trpc/server";
import { getHTTPStatusCodeFromError } from "@trpc/server/http";
@@ -27,11 +27,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
}
const input = getScheduleSchema.parse({ usernameList: slugs, isTeamEvent: parsedIsTeamEvent, ...rest });
const timeZoneSupported = input.timeZone ? isSupportedTimeZone(input.timeZone) : false;
const availableSlotsService = new AvailableSlotsService();
const availableSlots = await availableSlotsService.getAvailableSlots({
ctx: await createContext({ req, res }),
input,
});
const availableSlots = await getAvailableSlots({ ctx: await createContext({ req, res }), input });
const slotsInProvidedTimeZone = timeZoneSupported
? Object.keys(availableSlots.slots).reduce(
(acc: Record<string, { time: string; attendees?: number; bookingUid?: string }[]>, date) => {
+1 -1
View File
@@ -38,7 +38,7 @@
"@axiomhq/winston": "^1.2.0",
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.243",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.241",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
"@calcom/prisma": "*",
@@ -17,7 +17,7 @@ import {
VERSION_2024_08_13,
} from "@calcom/platform-constants";
import { TRPCError } from "@calcom/platform-libraries";
import { AvailableSlotsService } from "@calcom/platform-libraries/slots";
import { getAvailableSlots } from "@calcom/platform-libraries/slots";
import { RemoveSelectedSlotInput_2024_04_15, ReserveSlotInput_2024_04_15 } from "@calcom/platform-types";
import { ApiResponse, GetAvailableSlotsInput_2024_04_15 } from "@calcom/platform-types";
@@ -170,10 +170,8 @@ export class SlotsController_2024_04_15 {
: query.isTeamEvent;
// Do not use workers in E2E, not supported by TS-JEST
const availableSlotsService = this.config.get<boolean>("e2e") ? new AvailableSlotsService() : null;
const availableSlots = availableSlotsService
? await availableSlotsService.getAvailableSlots({
const availableSlots = this.config.get<boolean>("e2e")
? await getAvailableSlots({
input: {
...query,
isTeamEvent,
@@ -1,13 +1,11 @@
import { parentPort } from "worker_threads";
import { AvailableSlotsService } from "@calcom/platform-libraries/slots";
import { getAvailableSlots } from "@calcom/platform-libraries/slots";
parentPort?.on("message", async (data) => {
try {
const { input, ctx } = data;
const availableSlotsService = new AvailableSlotsService();
const result = await availableSlotsService.getAvailableSlots({ input, ctx });
const result = await getAvailableSlots({ input, ctx });
parentPort?.postMessage({ success: true, data: result });
} catch (error) {
parentPort?.postMessage({
@@ -17,7 +17,7 @@ import {
import { DateTime } from "luxon";
import { z } from "zod";
import { AvailableSlotsService } from "@calcom/platform-libraries/slots";
import { getAvailableSlots } from "@calcom/platform-libraries/slots";
import { GetSlotsInput_2024_09_04, ReserveSlotInput_2024_09_04 } from "@calcom/platform-types";
import { Booking, EventType } from "@calcom/prisma/client";
@@ -31,8 +31,6 @@ const DEFAULT_RESERVATION_DURATION = 5;
@Injectable()
export class SlotsService_2024_09_04 {
private readonly availableSlotsService: AvailableSlotsService;
constructor(
private readonly eventTypeRepository: EventTypesRepository_2024_06_14,
private readonly slotsRepository: SlotsRepository_2024_09_04,
@@ -41,14 +39,12 @@ export class SlotsService_2024_09_04 {
private readonly membershipsService: MembershipsService,
private readonly membershipsRepository: MembershipsRepository,
private readonly teamsRepository: TeamsRepository
) {
this.availableSlotsService = new AvailableSlotsService();
}
) {}
async getAvailableSlots(query: GetSlotsInput_2024_09_04) {
try {
const queryTransformed = await this.slotsInputService.transformGetSlotsQuery(query);
const availableSlots: TimeSlots = await this.availableSlotsService.getAvailableSlots({
const availableSlots: TimeSlots = await getAvailableSlots({
input: {
...queryTransformed,
routingFormResponseId: queryTransformed.routingFormResponseId ?? undefined,
@@ -8,7 +8,7 @@ import type { TGetRetellLLMSchema } from "@calcom/features/ee/cal-ai-phone/zod-u
import { fetcher } from "@calcom/lib/retellAIFetcher";
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
import prisma from "@calcom/prisma";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
dayjs.extend(advancedFormat);
@@ -86,9 +86,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const startTime = now.startOf("month").toISOString();
const endTime = now.add(2, "month").endOf("month").toISOString();
const orgSlug = eventType?.team?.parent?.slug ?? null;
const availableSlotsService = new AvailableSlotsService();
const availableSlots = await availableSlotsService.getAvailableSlots({
const availableSlots = await getAvailableSlots({
input: {
startTime,
endTime,
+90 -95
View File
@@ -17,7 +17,7 @@ import { describe, vi, test } from "vitest";
import dayjs from "@calcom/dayjs";
import { SchedulingType, type BookingStatus } from "@calcom/prisma/enums";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect, expectedSlotsForSchedule } from "./getSchedule/expects";
import { setupAndTeardown } from "./getSchedule/setupAndTeardown";
@@ -31,7 +31,6 @@ vi.mock("@calcom/lib/constants", () => ({
}));
describe("getSchedule", () => {
const availableSlotsService = new AvailableSlotsService();
setupAndTeardown();
// TODO: Move these inside describe('Team Event')
@@ -114,7 +113,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -135,7 +134,7 @@ describe("getSchedule", () => {
}
);
const scheduleWithoutLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithoutLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -263,7 +262,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleFixedHostLead = await availableSlotsService.getAvailableSlots({
const scheduleFixedHostLead = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -292,7 +291,7 @@ describe("getSchedule", () => {
}
);
const scheduleRRHostLead = await availableSlotsService.getAvailableSlots({
const scheduleRRHostLead = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -393,7 +392,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -527,7 +526,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -624,7 +623,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -733,7 +732,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -830,7 +829,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithLeadSkip = await availableSlotsService.getAvailableSlots({
const scheduleWithLeadSkip = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -927,7 +926,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWhenContactOwnerIsSkipped = await availableSlotsService.getAvailableSlots({
const scheduleWhenContactOwnerIsSkipped = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1031,7 +1030,7 @@ describe("getSchedule", () => {
});
// Day Plus 2 is completely free - It only has non accepted bookings
const scheduleOnCompletelyFreeDay = await availableSlotsService.getAvailableSlots({
const scheduleOnCompletelyFreeDay = await getSchedule({
input: {
eventTypeId: 1,
// EventTypeSlug doesn't matter for non-dynamic events
@@ -1065,7 +1064,7 @@ describe("getSchedule", () => {
);
// Day plus 3
const scheduleForDayWithOneBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithOneBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1131,7 +1130,7 @@ describe("getSchedule", () => {
});
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
const scheduleForEventWith30Length = await availableSlotsService.getAvailableSlots({
const scheduleForEventWith30Length = await getSchedule({
input: {
orgSlug: null,
eventTypeId: 1,
@@ -1168,18 +1167,17 @@ describe("getSchedule", () => {
}
);
const scheduleForEventWith30minsLengthAndSlotInterval2hrs =
await availableSlotsService.getAvailableSlots({
input: {
orgSlug: null,
eventTypeId: 2,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: false,
},
});
const scheduleForEventWith30minsLengthAndSlotInterval2hrs = await getSchedule({
input: {
orgSlug: null,
eventTypeId: 2,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: false,
},
});
// `slotInterval` takes precedence over `length`
// 4:30 is utc so it is 10:00 in IST
expect(scheduleForEventWith30minsLengthAndSlotInterval2hrs).toHaveTimeSlots(
@@ -1229,7 +1227,7 @@ describe("getSchedule", () => {
// Time Travel to the beginning of today after getting all the dates correctly.
timeTravelToTheBeginningOfToday({ utcOffsetInHours: 5.5 });
const scheduleForEventWithBookingNotice13Hrs = await availableSlotsService.getAvailableSlots({
const scheduleForEventWithBookingNotice13Hrs = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1253,7 +1251,7 @@ describe("getSchedule", () => {
}
);
const scheduleForEventWithBookingNotice10Hrs = await availableSlotsService.getAvailableSlots({
const scheduleForEventWithBookingNotice10Hrs = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -1316,7 +1314,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEventOnADayWithNonCalBooking = await availableSlotsService.getAvailableSlots({
const scheduleForEventOnADayWithNonCalBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1391,7 +1389,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEventOnADayWithCalBooking = await availableSlotsService.getAvailableSlots({
const scheduleForEventOnADayWithCalBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1450,7 +1448,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1515,7 +1513,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEventOnADayWithDateOverride = await availableSlotsService.getAvailableSlots({
const scheduleForEventOnADayWithDateOverride = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1594,7 +1592,7 @@ describe("getSchedule", () => {
// Requesting this user's availability for their
// individual Event Type
const thisUserAvailability = await availableSlotsService.getAvailableSlots({
const thisUserAvailability = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -1707,7 +1705,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const thisUserAvailabilityBookingLimitOne = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityBookingLimitOne = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1719,7 +1717,7 @@ describe("getSchedule", () => {
},
});
const thisUserAvailabilityBookingLimitTwo = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityBookingLimitTwo = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -1835,7 +1833,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const thisUserAvailabilityDurationLimitReached = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityDurationLimitReached = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1847,7 +1845,7 @@ describe("getSchedule", () => {
},
});
const thisUserAvailabilityDurationLimitNotReached = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityDurationLimitNotReached = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -1945,7 +1943,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const thisUserAvailabilityDurationLimit = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityDurationLimit = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2041,7 +2039,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const weeklyAvailability = await availableSlotsService.getAvailableSlots({
const weeklyAvailability = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2171,7 +2169,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const availabilityEventTypeOne = await availableSlotsService.getAvailableSlots({
const availabilityEventTypeOne = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2192,7 +2190,7 @@ describe("getSchedule", () => {
expect(availableSlotsInTz.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(0);
const availabilityEventTypeTwo = await availableSlotsService.getAvailableSlots({
const availabilityEventTypeTwo = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -2213,7 +2211,7 @@ describe("getSchedule", () => {
expect(availableSlotsInTz2.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(0);
const availabilityUserEventType = await availableSlotsService.getAvailableSlots({
const availabilityUserEventType = await getSchedule({
input: {
eventTypeId: 3,
eventTypeSlug: "",
@@ -2329,7 +2327,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const eventType1Availability = await availableSlotsService.getAvailableSlots({
const eventType1Availability = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2341,7 +2339,7 @@ describe("getSchedule", () => {
},
});
const eventType2Availability = await availableSlotsService.getAvailableSlots({
const eventType2Availability = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -2389,7 +2387,7 @@ describe("getSchedule", () => {
],
});
const eventType2AvailabilityUpdated = await availableSlotsService.getAvailableSlots({
const eventType2AvailabilityUpdated = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -2470,7 +2468,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const thisUserAvailabilityBookingLimit = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityBookingLimit = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2585,7 +2583,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const availabilityEventTypeOne = await availableSlotsService.getAvailableSlots({
const availabilityEventTypeOne = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2606,7 +2604,7 @@ describe("getSchedule", () => {
expect(availableSlotsInTz.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(0); // 1 booking per day as limit
const availabilityEventTypeTwo = await availableSlotsService.getAvailableSlots({
const availabilityEventTypeTwo = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -2626,7 +2624,7 @@ describe("getSchedule", () => {
expect(availableSlotsInTz.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(0); // 1 booking per day as limit
const availabilityUserEventType = await availableSlotsService.getAvailableSlots({
const availabilityUserEventType = await getSchedule({
input: {
eventTypeId: 3,
eventTypeSlug: "",
@@ -2710,7 +2708,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const thisUserAvailabilityBookingLimit = await availableSlotsService.getAvailableSlots({
const thisUserAvailabilityBookingLimit = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2793,7 +2791,7 @@ describe("getSchedule", () => {
// Requesting this user's availability for their
// individual Event Type
const thisUserAvailability = await availableSlotsService.getAvailableSlots({
const thisUserAvailability = await getSchedule({
input: {
eventTypeId: 2,
eventTypeSlug: "",
@@ -2864,7 +2862,7 @@ describe("getSchedule", () => {
],
});
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2963,7 +2961,7 @@ describe("getSchedule", () => {
],
});
const scheduleForTeamEventOnADayWithNoBooking = await availableSlotsService.getAvailableSlots({
const scheduleForTeamEventOnADayWithNoBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -2994,18 +2992,17 @@ describe("getSchedule", () => {
}
);
const scheduleForTeamEventOnADayWithOneBookingForEachUser =
await availableSlotsService.getAvailableSlots({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
const scheduleForTeamEventOnADayWithOneBookingForEachUser = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
// A user with blocked time in another event, still affects Team Event availability
// It's a collective availability, so both user 101 and 102 are considered for timeslots
@@ -3104,18 +3101,17 @@ describe("getSchedule", () => {
},
],
});
const scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots =
await availableSlotsService.getAvailableSlots({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
const scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
// A user with blocked time in another event, still affects Team Event availability
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots).toHaveTimeSlots(
[
@@ -3134,18 +3130,17 @@ describe("getSchedule", () => {
{ dateString: plus2DateString }
);
const scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot =
await availableSlotsService.getAvailableSlots({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus2DateString}T18:30:00.000Z`,
endTime: `${plus3DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
const scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus2DateString}T18:30:00.000Z`,
endTime: `${plus3DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
orgSlug: null,
},
});
// A user with blocked time in another event, still affects Team Event availability
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot).toHaveTimeSlots(
[
@@ -3200,7 +3195,7 @@ describe("getSchedule", () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
const getScheduleRes = await availableSlotsService.getAvailableSlots({
const getScheduleRes = await getSchedule({
input: {
eventTypeSlug: scenario.eventTypes[0]?.slug,
startTime: `${plus1DateString}T18:30:00.000Z`,
@@ -3280,7 +3275,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithHostChoosenSch = await availableSlotsService.getAvailableSlots({
const scheduleWithHostChoosenSch = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -3346,7 +3341,7 @@ describe("getSchedule", () => {
bookings: [],
});
const scheduleWithEventCommonSch = await availableSlotsService.getAvailableSlots({
const scheduleWithEventCommonSch = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -3427,7 +3422,7 @@ describe("getSchedule", () => {
],
});
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -3508,7 +3503,7 @@ describe("getSchedule", () => {
],
});
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -9,13 +9,12 @@ import {
import { describe, test } from "vitest";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect, expectedSlotsForSchedule } from "./expects";
import { setupAndTeardown } from "./setupAndTeardown";
describe("getSchedule", () => {
const availableSlotsService = new AvailableSlotsService();
setupAndTeardown();
describe("Calendar event", () => {
test("correctly identifies unavailable slots from selected calendars at user level", async () => {
@@ -64,7 +63,7 @@ describe("getSchedule", () => {
// An event with one accepted booking
await createBookingScenario(scenarioData);
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -134,7 +133,7 @@ describe("getSchedule", () => {
// An event with one accepted booking
await createBookingScenario(scenarioData);
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId,
eventTypeSlug: "",
@@ -203,7 +202,7 @@ describe("getSchedule", () => {
// An event with one accepted booking
await createBookingScenario(scenarioData);
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId,
eventTypeSlug: "",
@@ -276,7 +275,7 @@ describe("getSchedule", () => {
// An event with one accepted booking
await createBookingScenario(scenarioData);
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId,
eventTypeSlug: "",
@@ -13,14 +13,13 @@ import { expectNoAttemptToGetAvailability } from "../../utils/bookingScenario/ex
import { describe, test } from "vitest";
import { MembershipRole } from "@calcom/prisma/enums";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect, expectedSlotsForSchedule } from "./expects";
import { setupAndTeardown } from "./setupAndTeardown";
describe("getSchedule", () => {
setupAndTeardown();
describe("Delegation Credential", () => {
test("correctly identifies unavailable slots using DelegationCredential credentials", async () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
@@ -90,8 +89,8 @@ describe("getSchedule", () => {
};
await createBookingScenario(scenarioData);
const availableSlotsService = new AvailableSlotsService();
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -182,8 +181,8 @@ describe("getSchedule", () => {
};
await createBookingScenario(scenarioData);
const availableSlotsService = new AvailableSlotsService();
const scheduleForDayWithAGoogleCalendarBooking = await availableSlotsService.getAvailableSlots({
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -9,7 +9,7 @@ import type { ScenarioData } from "../../utils/bookingScenario/bookingScenario";
import { describe, expect, vi, test } from "vitest";
import { PeriodType } from "@calcom/prisma/enums";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expectedSlotsForSchedule } from "./expects";
import { setupAndTeardown } from "./setupAndTeardown";
@@ -70,7 +70,6 @@ vi.mock("@calcom/lib/constants", () => ({
}));
describe("getSchedule", () => {
const availableSlotsService = new AvailableSlotsService();
setupAndTeardown();
describe("Future Limits", () => {
describe("PeriodType=ROLLING", () => {
@@ -113,7 +112,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -201,7 +200,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -285,7 +284,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -380,7 +379,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -484,7 +483,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -574,7 +573,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -658,7 +657,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -781,7 +780,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -879,7 +878,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -980,7 +979,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1088,7 +1087,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1208,7 +1207,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1305,7 +1304,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1414,7 +1413,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1516,7 +1515,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEvent = await availableSlotsService.getAvailableSlots({
const scheduleForEvent = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -1602,7 +1601,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const scheduleForEventForPagoTz = await availableSlotsService.getAvailableSlots({
const scheduleForEventForPagoTz = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -11,7 +11,7 @@ import { describe, test, vi } from "vitest";
import type { z } from "zod";
import type { getScheduleSchema } from "@calcom/trpc/server/routers/viewer/slots/types";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect } from "./expects";
import { setupAndTeardown } from "./setupAndTeardown";
@@ -89,7 +89,6 @@ async function setupTeamAndFeatures() {
}
describe("getSchedule", () => {
const availableSlotsService = new AvailableSlotsService();
setupAndTeardown();
describe("Restriction Schedule", () => {
@@ -157,7 +156,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const result = await availableSlotsService.getAvailableSlots({
const result = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -253,7 +252,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const result = await availableSlotsService.getAvailableSlots({
const result = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -354,7 +353,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const result = await availableSlotsService.getAvailableSlots({
const result = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -439,7 +438,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const result = await availableSlotsService.getAvailableSlots({
const result = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
@@ -12,7 +12,7 @@ import type { z } from "zod";
import { prisma } from "@calcom/prisma";
import type { getScheduleSchema, GetScheduleOptions } from "@calcom/trpc/server/routers/viewer/slots/types";
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect } from "./expects";
import { setupAndTeardown } from "./setupAndTeardown";
@@ -62,7 +62,6 @@ const getBaseScenarioData = (): ScheduleScenario => ({
});
describe("getSchedule", () => {
const availableSlotsService = new AvailableSlotsService();
setupAndTeardown();
describe("Reserved Slots", () => {
@@ -94,7 +93,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
});
@@ -129,7 +128,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
ctx: {
req: {
@@ -184,7 +183,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
});
@@ -239,7 +238,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
});
@@ -288,7 +287,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
const schedule = await availableSlotsService.getAvailableSlots({
const schedule = await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
});
@@ -367,7 +366,7 @@ describe("getSchedule", () => {
await createBookingScenario(scenarioData);
await availableSlotsService.getAvailableSlots({
await getSchedule({
input: getTestScheduleInput({ yesterdayDateString, plus5DateString }),
ctx: {
req: {
-1
View File
@@ -116,7 +116,6 @@
},
"dependencies": {
"@daily-co/daily-js": "^0.76.0",
"@evyweb/ioctopus": "^1.2.0",
"@next/third-parties": "^14.2.5",
"@vercel/functions": "^1.4.0",
"city-timezones": "^1.2.1",
+2 -2
View File
@@ -1,3 +1,3 @@
import { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
export { AvailableSlotsService };
export { getAvailableSlots };
@@ -1,6 +1,6 @@
import type { IncomingMessage } from "http";
import { AvailableSlotsService } from "../slots/util";
import { getAvailableSlots } from "../slots/util";
import type { TGetTeamScheduleInputSchema } from "./getTeamSchedule.schema";
export type GetTeamScheduleOptions = {
@@ -13,6 +13,5 @@ interface ContextForGetSchedule extends Record<string, unknown> {
}
export const getTeamScheduleHandler = async ({ ctx, input }: GetTeamScheduleOptions) => {
const availableSlotsService = new AvailableSlotsService();
return await availableSlotsService.getAvailableSlots({ ctx, input });
return await getAvailableSlots({ ctx, input });
};
@@ -1,7 +1,6 @@
import type { GetScheduleOptions } from "./types";
import { AvailableSlotsService } from "./util";
import { getAvailableSlots } from "./util";
export const getScheduleHandler = async ({ ctx, input }: GetScheduleOptions) => {
const availableSlotsService = new AvailableSlotsService();
return await availableSlotsService.getAvailableSlots({ ctx, input });
return await getAvailableSlots({ ctx, input });
};
File diff suppressed because it is too large Load Diff
+5 -13
View File
@@ -2519,7 +2519,7 @@ __metadata:
"@axiomhq/winston": ^1.2.0
"@calcom/platform-constants": "*"
"@calcom/platform-enums": "*"
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.243"
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.241"
"@calcom/platform-types": "*"
"@calcom/platform-utils": "*"
"@calcom/prisma": "*"
@@ -3565,13 +3565,13 @@ __metadata:
languageName: unknown
linkType: soft
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.243":
version: 0.0.243
resolution: "@calcom/platform-libraries@npm:0.0.243"
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.241":
version: 0.0.241
resolution: "@calcom/platform-libraries@npm:0.0.241"
dependencies:
"@calcom/features": "*"
"@calcom/lib": "*"
checksum: ce0a4778857a62a6df46b1c0b419fbaad1d874d7b0da92d43589348f6e07a7de912703692c9fbc1e21fb2e0bf4d323bcd7eae96b5198376216216c872374cc09
checksum: 1eec9dce749b6678427e00d0f2d2f383d798066f2f7ef7aca1ce90d5c649ed41d2fc1496be93c7448e7c22d2e015e333c8fe0b81b7c3b04b9637f6ea1910a898
languageName: node
linkType: hard
@@ -5816,13 +5816,6 @@ __metadata:
languageName: node
linkType: hard
"@evyweb/ioctopus@npm:^1.2.0":
version: 1.2.0
resolution: "@evyweb/ioctopus@npm:1.2.0"
checksum: f48382e2dfab9b48b59d02a0718ddbb8e9d81cbb6d214eb42b5378c2b9d9f9f8decb5b13019600972252e5b6c204901ebfbc36000a4a8ea0f69d6fd8b3417458
languageName: node
linkType: hard
"@ewsjs/ntlm-client@npm:^3.0.1":
version: 3.0.1
resolution: "@ewsjs/ntlm-client@npm:3.0.1"
@@ -21773,7 +21766,6 @@ __metadata:
"@changesets/changelog-github": ^0.5.1
"@changesets/cli": 2.29.4
"@daily-co/daily-js": ^0.76.0
"@evyweb/ioctopus": ^1.2.0
"@jetstreamapp/soql-parser-js": ^6.1.0
"@next/third-parties": ^14.2.5
"@playwright/test": ^1.45.3