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

This commit is contained in:
Benny Joo authored and GitHub committed 2025-07-08 14:28:59 -07:00
1 parent c3dab3e4f8
commit 02321c33b2
18 files changed
+1271 -1331

No files matched your search

+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/[email protected]3",
"@calcom/platform-libraries": "npm:@calcom/[email protected]1",
"@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,