refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository (#22705)

* refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository

- Rename class from SelectedSlotsRepository to PrismaSelectedSlotRepository for consistency
- Update all imports and type references throughout the codebase
- Update DI module bindings and variable names
- Maintain type safety without breaking changes

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

* refactor: complete PrismaSelectedSlotRepository rename

- Update DI module binding property name from selectedSlotsRepo to selectedSlotRepo
- Update test mock to use PrismaSelectedSlotRepository class name
- Ensure all references are consistently updated

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

* fix: rename file to prismaSelectedSlotRepository.ts and fix plural variable references

- Rename apps/api/v2/src/lib/repositories/prisma-selected-slots.repository.ts to prismaSelectedSlotRepository.ts
- Update class name from PrismaSelectedSlotsRepository to PrismaSelectedSlotRepository
- Fix plural variable reference selectedSlotsRepository to selectedSlotRepository in service
- Update all import paths to reference the new file name
- Maintain consistency with camelCase naming convention

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

* fix: rename SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture for consistency

- Rename test fixture class from SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture (singular)
- Update all import statements in test files to use the renamed class
- Resolves naming mismatch between fixture class and variable declarations
- Fixes TypeScript compilation errors in CI tests

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

* feat: add SelectedSlotRepositoryInterface and update DI to use interface

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

* refactor: rename selectedSlots.ts to selectedSlot.ts and update all imports

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

* fix: update test mock import path after file rename

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

* Update apps/api/v2/src/lib/modules/available-slots.module.ts

* Update apps/api/v2/src/lib/modules/available-slots.module.ts

* Implement DTO

* dont declare dependencies locally, duplicating

* Small DTO/token fix

* chore: bump @calcom/platform-libraries from 0.0.266 to 0.0.267

* oops.

* Update fixture names also

* Omg these vscode actions preventing saves

* Final fix, hopefully

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Somay Chauhan <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-25 16:59:32 -07:00
1 parent 9ccf5f3723
commit fde1d671fb
26 files changed
+120 -93

No files matched your search

@@ -2,8 +2,8 @@ import type { NextApiRequest } from "next";
import { HttpError } from "@calcom/lib/http-error";
import { getPastTimeAndMinimumBookingNoticeBoundsStatus } from "@calcom/lib/isOutOfBounds";
import { PrismaSelectedSlotRepository } from "@calcom/lib/server/repository/PrismaSelectedSlotRepository";
import { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
import { SelectedSlotsRepository } from "@calcom/lib/server/repository/selectedSlots";
import type { PrismaClient } from "@calcom/prisma";
import type { TIsAvailableInputSchema, TIsAvailableOutputSchema } from "./isAvailable.schema";
@@ -41,7 +41,7 @@ export const isAvailableHandler = async ({
// Check each slot's availability
// Without uid, we must not check for reserved slots because if uuid isn't set in cookie yet, but it is going to be through reserveSlot request soon, we could consider the slot as reserved accidentally.
const slotsRepo = new SelectedSlotsRepository(ctx.prisma);
const slotsRepo = new PrismaSelectedSlotRepository(ctx.prisma);
const reservedSlots = uid ? await slotsRepo.findManyReservedByOthers(slots, eventTypeId, uid) : [];
// Map all slots to their availability status
@@ -5,15 +5,15 @@ import { vi, describe, it, expect, afterEach } from "vitest";
// reserveSlotHandler relies on WEBAPP_URL being evaluated at import time, so we need to reset modules
// between tests after tweaking process.env to simulate different deployment environments.
//
// The handler also calls into Prisma and the SelectedSlotsRepository, so we stub those parts out.
// The handler also calls into Prisma and the SelectedSlotRepository, so we stub those parts out.
// We alias the module path once we know WEBAPP_URL has been configured.
const dynamicImportHandler = async () => await import("./reserveSlot.handler");
// The repository instance method is used to check for an existing reservation by someone else.
// To keep this unit test isolated from the database layer, we stub this to always resolve falsey.
vi.mock("@calcom/lib/server/repository/selectedSlots", () => ({
SelectedSlotsRepository: vi.fn().mockImplementation(() => ({
vi.mock("@calcom/lib/server/repository/PrismaSelectedSlotRepository", () => ({
PrismaSelectedSlotRepository: vi.fn().mockImplementation(() => ({
findReservedByOthers: vi.fn().mockResolvedValue(null),
})),
}));
@@ -5,7 +5,7 @@ import { v4 as uuid } from "uuid";
import dayjs from "@calcom/dayjs";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { MINUTES_TO_BOOK } from "@calcom/lib/constants";
import { SelectedSlotsRepository } from "@calcom/lib/server/repository/selectedSlots";
import { PrismaSelectedSlotRepository } from "@calcom/lib/server/repository/PrismaSelectedSlotRepository";
import type { PrismaClient } from "@calcom/prisma";
import { BookingStatus } from "@calcom/prisma/enums";
@@ -64,7 +64,7 @@ export const reserveSlotHandler = async ({ ctx, input }: ReserveSlotOptions) =>
}
// Check for existing reservations for the same slot
const slotsRepo = new SelectedSlotsRepository(prisma);
const slotsRepo = new PrismaSelectedSlotRepository(prisma);
const reservedBySomeoneElse = await slotsRepo.findReservedByOthers({
slot: {
utcStartIso: slotUtcStartDate,
@@ -42,12 +42,12 @@ import { isRestrictionScheduleEnabled } from "@calcom/lib/restrictionSchedule";
import { safeStringify } from "@calcom/lib/safeStringify";
import { withReporting } from "@calcom/lib/sentryWrapper";
import { getTotalBookingDuration } from "@calcom/lib/server/queries/booking";
import type { ISelectedSlotRepository } from "@calcom/lib/server/repository/ISelectedSlotRepository";
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
import type { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
import type { RoutingFormResponseRepository } from "@calcom/lib/server/repository/formResponse";
import type { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
import type { ScheduleRepository } from "@calcom/lib/server/repository/schedule";
import type { SelectedSlotsRepository } from "@calcom/lib/server/repository/selectedSlots";
import type { TeamRepository } from "@calcom/lib/server/repository/team";
import type { UserRepository } from "@calcom/lib/server/repository/user";
import { withSelectedCalendars } from "@calcom/lib/server/repository/user";
@@ -93,7 +93,7 @@ export type GetAvailableSlotsResponse = Awaited<
export interface IAvailableSlotsService {
oooRepo: PrismaOOORepository;
scheduleRepo: ScheduleRepository;
selectedSlotsRepo: SelectedSlotsRepository;
selectedSlotRepo: ISelectedSlotRepository;
teamRepo: TeamRepository;
userRepo: UserRepository;
bookingRepo: BookingRepository;
@@ -114,7 +114,7 @@ export class AvailableSlotsService {
eventTypeId: number;
}) {
const currentTimeInUtc = dayjs.utc().format();
const slotsRepo = this.dependencies.selectedSlotsRepo;
const slotsRepo = this.dependencies.selectedSlotRepo;
const unexpiredSelectedSlots =
(await slotsRepo.findManyUnexpiredSlots({