Skip to content

Comments

refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository#22705

Merged
emrysal merged 18 commits intomainfrom
devin/refactor-selected-slot-repository-1753285781
Jul 25, 2025
Merged

refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository#22705
emrysal merged 18 commits intomainfrom
devin/refactor-selected-slot-repository-1753285781

Conversation

@emrysal
Copy link
Contributor

@emrysal emrysal commented Jul 23, 2025

refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository

Summary

This PR refactors the SelectedSlotsRepository class to PrismaSelectedSlotRepository for naming consistency across the Cal.com codebase. The change affects the main repository class definition, all imports/exports, type definitions, dependency injection bindings, test mocks, and variable names throughout the codebase.

Key Changes:

  • Renamed SelectedSlotsRepositoryPrismaSelectedSlotRepository in the main class definition
  • Updated all imports and type references across tRPC handlers, DI modules, and test files
  • Updated variable names from selectedSlotsReposelectedSlotRepo for consistency
  • Updated test mocks to use the new class name
  • Maintained all existing functionality without breaking changes

Review & Testing Checklist for Human

  • Run full test suite - Verify all tests pass, especially slot reservation and availability tests in apps/api/v2/src/modules/slots/
  • Test slot booking end-to-end - Create a test booking to ensure slot reservation functionality works correctly
  • Verify dependency injection - Check that the DI container initializes properly without injection errors
  • Search for remaining references - Search codebase for any remaining instances of "SelectedSlotsRepository" or "selectedSlotsRepo" that may have been missed
  • Check TypeScript compilation - Run yarn type-check:ci to ensure no type errors were introduced

Recommended test plan: Book a slot through the UI, verify it appears as reserved, and confirm the reservation expires properly after the timeout period.


Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    A["packages/lib/server/repository/<br/>selectedSlots.ts"]:::major-edit
    B["packages/platform/libraries/<br/>repositories.ts"]:::minor-edit
    C["packages/trpc/server/routers/<br/>viewer/slots/util.ts"]:::minor-edit
    D["packages/trpc/server/routers/<br/>viewer/slots/reserveSlot.handler.ts"]:::minor-edit
    E["packages/trpc/server/routers/<br/>viewer/slots/isAvailable.handler.ts"]:::minor-edit
    F["packages/lib/di/modules/<br/>selectedSlots.ts"]:::minor-edit
    G["Test Files"]:::minor-edit
    H["DI Container"]:::context

    A -->|exports| B
    A -->|imported by| D
    A -->|imported by| E
    A -->|type imported by| C
    F -->|binds class| A
    H -->|injects| A
    D -->|uses| A
    E -->|uses| A
    G -->|mocks| A

    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit
        L3["Context/No Edit"]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Type checking passed locally with yarn type-check:ci returning success
  • Lint-staged hooks completed successfully during commits
  • This is a pure refactoring with no functional changes to slot reservation logic
  • The change maintains backward compatibility through the export alias in packages/platform/libraries/repositories.ts

Session Info:

devin-ai-integration bot and others added 2 commits July 23, 2025 15:59
- 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: alex@cal.com <me@alexvanandel.com>
- 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: alex@cal.com <me@alexvanandel.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

Walkthrough

This change set systematically refactors the codebase to rename the repository handling selected slots from the plural form (SelectedSlotsRepository, PrismaSelectedSlotsRepository) to the singular form (PrismaSelectedSlotRepository, SelectedSlotRepositoryFixture, etc.) across all relevant modules, dependency injection tokens, imports, exports, and test fixtures. It introduces a new interface (ISelectedSlotRepository) and DTO type (SelectedSlot) to define repository contracts and data shapes. Custom types and methods related to the old repository are removed or replaced with direct usage of Prisma types and methods. Dependency injection bindings, tokens, and module registrations are updated to reflect the new naming. Test files and service constructors are also adjusted for consistency with the new repository naming and interface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

  • Complexity: Moderate. The changes are broad and affect many files across multiple layers (repositories, DI, services, tests), but are primarily systematic renaming and interface introduction, with some removal of custom types and method refactoring.
  • Estimated review time: 15–20 minutes, as reviewers will need to verify naming consistency, interface contracts, and the absence of logic changes or regressions across the affected modules and tests.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/apps/api/v2".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "apps/api/v2/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1110fe and aa6d856.

📒 Files selected for processing (1)
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts (14 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/refactor-selected-slot-repository-1753285781

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

…riable 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: alex@cal.com <me@alexvanandel.com>
@vercel
Copy link

vercel bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 25, 2025 10:39pm
cal-eu ⬜️ Ignored (Inspect) Jul 25, 2025 10:39pm

…ixture 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: alex@cal.com <me@alexvanandel.com>
Co-Authored-By: alex@cal.com <me@alexvanandel.com>
@emrysal emrysal marked this pull request as ready for review July 23, 2025 18:36
@emrysal emrysal requested a review from a team as a code owner July 23, 2025 18:36
@emrysal emrysal requested a review from a team July 23, 2025 18:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts (2)

33-33: Import path is still plural – consider renaming file for consistency

The class has been renamed to SelectedSlotRepositoryFixture, but the file path remains selected-slots.repository.fixture.ts.
Keeping class and filename in sync helps future grepping / auto-import tools.
(Not blocking, just a heads-up.)


486-487: Repeated clean-up calls – consider helper to DRY tests

selectedSlotRepositoryFixture.getByUid / deleteByUId appear in many assertions/teardowns.
A small helper (e.g. await assertSlotReleased(uid, mins)) would reduce duplication and make intent clearer.

Also applies to: 620-621, 722-730, 778-786, 1400-1408, 1677-1678, 1875-1876, 1905-1907, 1921-1932

apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.ts (1)

19-20: Import updated correctly – but keep an eye on plural file path

Same note as elsewhere: class is singular while file name is still selected-slots.repository.fixture.ts. Optional, but renaming file keeps things coherent.

packages/lib/server/repository/selectedSlots.ts (1)

84-100: Method now directly calls prismaClient instead of using internal method.

The findManyReservedByOthers method changed from using the internal findMany method to directly calling this.prismaClient.selectedSlots.findMany. While this works, it creates inconsistency in the codebase where some methods use internal methods and others don't.

Consider using the internal findMany method for consistency:

 async findManyReservedByOthers(slots: TimeSlot[], eventTypeId: number, uid: string) {
-  return await this.prismaClient.selectedSlots.findMany({
+  return await this.findMany({
     where: {
       OR: slots.map((slot) => ({
         slotUtcStartDate: slot.utcStartIso,
         slotUtcEndDate: slot.utcEndIso,
         eventTypeId,
         uid: { not: uid },
         releaseAt: { gt: new Date() },
       })),
     },
     select: {
       slotUtcStartDate: true,
       slotUtcEndDate: true,
     },
   });
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c88ed8c and bc611a4.

📒 Files selected for processing (15)
  • apps/api/v2/src/lib/modules/available-slots.module.ts (2 hunks)
  • apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.ts (1 hunks)
  • apps/api/v2/src/lib/services/available-slots.service.ts (3 hunks)
  • apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.ts (4 hunks)
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/team-event-type-slots.controller.e2e-spec.ts (4 hunks)
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts (14 hunks)
  • apps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.ts (1 hunks)
  • packages/lib/di/modules/available-slots.ts (1 hunks)
  • packages/lib/di/modules/selectedSlots.ts (1 hunks)
  • packages/lib/server/repository/selectedSlots.ts (2 hunks)
  • packages/platform/libraries/repositories.ts (1 hunks)
  • packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts (2 hunks)
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.test.ts (1 hunks)
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts (2 hunks)
  • packages/trpc/server/routers/viewer/slots/util.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.

Files:

  • packages/trpc/server/routers/viewer/slots/util.ts
  • apps/api/v2/src/lib/modules/available-slots.module.ts
  • apps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.ts
  • packages/platform/libraries/repositories.ts
  • packages/lib/di/modules/available-slots.ts
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.test.ts
  • apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.ts
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts
  • packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts
  • apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.ts
  • packages/lib/di/modules/selectedSlots.ts
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts
  • apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/team-event-type-slots.controller.e2e-spec.ts
  • apps/api/v2/src/lib/services/available-slots.service.ts
  • packages/lib/server/repository/selectedSlots.ts
🧠 Learnings (7)
apps/api/v2/src/lib/modules/available-slots.module.ts (4)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Include selects the relationship AND all the fields of the table the relationship belongs to.

apps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.ts (1)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

packages/platform/libraries/repositories.ts (4)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Include selects the relationship AND all the fields of the table the relationship belongs to.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.ts (4)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Include selects the relationship AND all the fields of the table the relationship belongs to.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts (3)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts (3)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

packages/lib/server/repository/selectedSlots.ts (4)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Include selects the relationship AND all the fields of the table the relationship belongs to.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

🧬 Code Graph Analysis (7)
packages/trpc/server/routers/viewer/slots/util.ts (1)
packages/lib/server/repository/selectedSlots.ts (1)
  • SelectedSlotRepositoryInterface (23-49)
apps/api/v2/src/lib/modules/available-slots.module.ts (1)
packages/platform/libraries/repositories.ts (1)
  • PrismaSelectedSlotRepository (6-6)
packages/lib/di/modules/available-slots.ts (1)
packages/lib/di/tokens.ts (1)
  • DI_TOKENS (1-23)
packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts (1)
packages/lib/server/repository/selectedSlots.ts (1)
  • PrismaSelectedSlotRepository (51-140)
packages/lib/di/modules/selectedSlots.ts (2)
packages/lib/di/tokens.ts (1)
  • DI_TOKENS (1-23)
packages/lib/server/repository/selectedSlots.ts (1)
  • PrismaSelectedSlotRepository (51-140)
apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts (1)
apps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.ts (1)
  • SelectedSlotRepositoryFixture (6-22)
apps/api/v2/src/lib/services/available-slots.service.ts (1)
packages/lib/server/repository/selectedSlots.ts (1)
  • SelectedSlotRepositoryInterface (23-49)
🔇 Additional comments (21)
apps/api/v2/src/lib/modules/available-slots.module.ts (1)

8-8: LGTM! Import and provider registration updated consistently.

The import path and class name have been updated from the old PrismaSelectedSlotsRepository to PrismaSelectedSlotRepository, maintaining consistency with the repository renaming across the codebase.

Also applies to: 19-19

apps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.ts (1)

6-6: LGTM! Test fixture class name updated for consistency.

The class name has been updated from SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture, aligning with the repository renaming pattern from plural to singular form.

packages/lib/di/modules/selectedSlots.ts (1)

4-4: LGTM! DI module updated to use renamed repository class.

The import and class binding have been properly updated to use PrismaSelectedSlotRepository while maintaining the same DI token for backward compatibility. The constructor dependency injection remains unchanged.

Also applies to: 9-9

packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts (1)

6-6: LGTM! Handler updated to use renamed repository class.

The import and instantiation have been updated from SelectedSlotsRepository to PrismaSelectedSlotRepository. The handler logic and method calls remain unchanged, maintaining the same functionality.

Also applies to: 44-44

packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts (1)

8-8: LGTM! Handler updated to use renamed repository class.

The import and instantiation have been correctly updated from SelectedSlotsRepository to PrismaSelectedSlotRepository. All slot reservation logic and method calls remain unchanged, preserving the existing functionality.

Also applies to: 67-67

apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.ts (2)

8-8: LGTM: Class renaming is consistent.

The class has been correctly renamed from PrismaSelectedSlotsRepository to PrismaSelectedSlotRepository to follow singular naming convention.


4-4: No action required on PrismaSelectedSlotsRepository import

Verified that packages/platform/libraries/repositories.ts exports the class as:

export { PrismaSelectedSlotRepository as PrismaSelectedSlotsRepository } 

and the import in apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.ts correctly aliases that export:

import { PrismaSelectedSlotsRepository as PrismaSelectedSlotsRepositoryLib } from "@calcom/platform-libraries/repositories";

No renaming or additional changes are needed.

apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/team-event-type-slots.controller.e2e-spec.ts (3)

24-24: LGTM: Import statement correctly updated.

The import has been properly renamed from SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture.


47-47: LGTM: Variable type declaration correctly updated.

The variable type has been properly renamed to SelectedSlotRepositoryFixture.


371-371: LGTM: Method calls use correct variable name.

The method calls correctly use the renamed variable selectedSlotRepositoryFixture.

Also applies to: 378-378

packages/lib/di/modules/available-slots.ts (1)

12-12: Confirmed: selectedSlotRepo consistency

Verified that the IAvailableSlotsService interface in
packages/trpc/server/routers/viewer/slots/util.ts defines
selectedSlotRepo, matching the updated DI binding key. No further changes required.

packages/trpc/server/routers/viewer/slots/reserveSlot.handler.test.ts (2)

8-8: LGTM: Comment updated correctly.

The comment has been properly updated to reference SelectedSlotRepository instead of SelectedSlotsRepository.


16-16: LGTM: Mock class name updated correctly.

The mock implementation has been properly updated to use PrismaSelectedSlotRepository while maintaining the same stubbed functionality.

packages/platform/libraries/repositories.ts (1)

6-6: LGTM: Backward compatibility maintained through export alias.

The export correctly imports the renamed PrismaSelectedSlotRepository while maintaining backward compatibility by exporting it as PrismaSelectedSlotsRepository. This allows existing consumers to continue using the old export name.

apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts (1)

52-53: Rename looks correct – no functional impact

Variable declaration and instantiation updated to the singular form; everything compiles here.

Also applies to: 107-108

apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.ts (1)

775-777: After-all clean-up depends on the fix above

Once the type name is corrected, this statement remains valid. No further action required.

packages/trpc/server/routers/viewer/slots/util.ts (2)

50-50: Good use of dependency inversion principle!

Using the interface instead of the concrete implementation improves testability and follows SOLID principles.


96-96: Consistent naming convention applied.

The property and variable names have been correctly updated from plural to singular form, maintaining consistency with the new naming convention.

Also applies to: 117-117

apps/api/v2/src/lib/services/available-slots.service.ts (1)

10-10: Proper interface usage in NestJS service.

The service correctly uses the interface type for dependency injection, and the property name has been consistently updated to match the new singular naming convention.

Also applies to: 21-21, 31-31

packages/lib/server/repository/selectedSlots.ts (2)

51-51: Class rename aligns with naming convention.

The class has been properly renamed to PrismaSelectedSlotRepository and correctly implements the new interface.


95-98: Good practice: Selecting only required fields.

The Prisma queries correctly use select to fetch only the necessary fields, which improves performance and follows the established best practices.

Also applies to: 114-122

OR?: WhereCondition[];
};
select?: Prisma.SelectedSlotsSelect;
select?: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid using any type - reduces type safety.

The interface and implementation use any type extensively, which defeats TypeScript's type safety benefits. Consider defining proper types for method parameters.

Define proper types for the interface methods:

-export interface SelectedSlotRepositoryInterface {
-  findMany(args: any): Promise<any[]>;
-  findFirst(args: any): Promise<any | null>;
+export interface SelectedSlotRepositoryInterface {
+  findMany(args: FindManyArgs): Promise<any[]>;
+  findFirst(args: { where: WhereCondition }): Promise<any | null>;

And update the implementation:

-async findMany({ where, select }: any) {
+async findMany({ where, select }: FindManyArgs) {
   return await this.prismaClient.selectedSlots.findMany({ where, select });
 }

-async findFirst({ where }: any) {
+async findFirst({ where }: { where: WhereCondition }) {
   return await this.prismaClient.selectedSlots.findFirst({
     where,
   });
 }

Also applies to: 23-49, 54-54, 58-58

🤖 Prompt for AI Agents
In packages/lib/server/repository/selectedSlots.ts around lines 15, 23-49, 54,
and 58, the use of the `any` type for method parameters reduces type safety.
Identify the expected structure or type of the `select` parameter and other
parameters in these methods, then replace `any` with these specific types or
interfaces. Update the interface definitions and method implementations
accordingly to use these proper types, ensuring stronger type checking and
better code clarity.

…mports

Co-Authored-By: alex@cal.com <me@alexvanandel.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (3)
packages/lib/server/repository/selectedSlot.ts (3)

11-16: Consider using generics instead of any for better type safety.

The change from a Prisma-specific type to any reduces type safety. Consider using a generic type parameter to maintain type checking while keeping the interface decoupled from Prisma.

-export type FindManyArgs = {
+export type FindManyArgs<TSelect = any> = {
   where?: WhereCondition & {
     OR?: WhereCondition[];
   };
-  select?: any;
+  select?: TSelect;
 };

54-62: Maintain proper typing in the implementation methods.

Even if the interface uses generic types, the implementation should maintain proper Prisma types for type safety and better developer experience.

-  async findMany({ where, select }: any) {
+  async findMany({ where, select }: FindManyArgs) {
     return await this.prismaClient.selectedSlots.findMany({ where, select });
   }

-  async findFirst({ where }: any) {
+  async findFirst({ where }: { where: WhereCondition }) {
     return await this.prismaClient.selectedSlots.findFirst({
       where,
     });
   }

84-100: Maintain consistency by using the internal findMany method.

The method bypasses the internal findMany method and calls Prisma directly, which breaks the repository pattern's abstraction. This inconsistency could lead to maintenance issues if common logic needs to be added to all queries.

   async findManyReservedByOthers(slots: TimeSlot[], eventTypeId: number, uid: string) {
-    return await this.prismaClient.selectedSlots.findMany({
+    return await this.findMany({
       where: {
         OR: slots.map((slot) => ({
           slotUtcStartDate: slot.utcStartIso,
           slotUtcEndDate: slot.utcEndIso,
           eventTypeId,
           uid: { not: uid },
           releaseAt: { gt: new Date() },
         })),
       },
       select: {
         slotUtcStartDate: true,
         slotUtcEndDate: true,
       },
     });
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc611a4 and d275a12.

📒 Files selected for processing (8)
  • apps/api/v2/src/lib/repositories/prisma-selected-slots.repository.ts (1 hunks)
  • apps/api/v2/src/lib/services/available-slots.service.ts (3 hunks)
  • packages/lib/di/modules/selectedSlots.ts (1 hunks)
  • packages/lib/server/repository/selectedSlot.ts (2 hunks)
  • packages/platform/libraries/repositories.ts (1 hunks)
  • packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts (2 hunks)
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts (2 hunks)
  • packages/trpc/server/routers/viewer/slots/util.ts (3 hunks)
✅ Files skipped from review due to trivial changes (3)
  • packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts
  • packages/trpc/server/routers/viewer/slots/reserveSlot.handler.ts
  • apps/api/v2/src/lib/repositories/prisma-selected-slots.repository.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/lib/di/modules/selectedSlots.ts
  • packages/platform/libraries/repositories.ts
  • packages/trpc/server/routers/viewer/slots/util.ts
  • apps/api/v2/src/lib/services/available-slots.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.

Files:

  • packages/lib/server/repository/selectedSlot.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.
packages/lib/server/repository/selectedSlot.ts (4)

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Select selects only the fields you specify explicitly.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Only select data you need.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Include selects the relationship AND all the fields of the table the relationship belongs to.

Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-21T13:54:11.770Z
Learning: Applies to backend/**/*.{ts,tsx} : For Prisma queries: Never use Includes - use select.

🔇 Additional comments (1)
packages/lib/server/repository/selectedSlot.ts (1)

51-52: Good refactoring to improve naming consistency.

The rename to PrismaSelectedSlotRepository clearly indicates this is a Prisma-specific implementation and follows better naming conventions.

Comment on lines 23 to 49
export interface SelectedSlotRepositoryInterface {
findMany(args: any): Promise<any[]>;
findFirst(args: any): Promise<any | null>;
findReservedByOthers(args: { slot: TimeSlot; eventTypeId: number; uid: string }): Promise<any | null>;
findManyReservedByOthers(
slots: TimeSlot[],
eventTypeId: number,
uid: string
): Promise<
Array<{
slotUtcStartDate: Date;
slotUtcEndDate: Date;
}>
>;
findManyUnexpiredSlots(args: { userIds: number[]; currentTimeInUtc: string }): Promise<
Array<{
id: number;
slotUtcStartDate: Date;
slotUtcEndDate: Date;
userId: number | null;
isSeat: boolean;
eventTypeId: number;
uid: string;
}>
>;
deleteManyExpiredSlots(args: { eventTypeId: number; currentTimeInUtc: string }): Promise<{ count: number }>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety in the interface definition.

The interface uses any types extensively, which removes compile-time type checking. Consider using generics or more specific types to maintain type safety while achieving abstraction from Prisma.

-export interface SelectedSlotRepositoryInterface {
-  findMany(args: any): Promise<any[]>;
-  findFirst(args: any): Promise<any | null>;
-  findReservedByOthers(args: { slot: TimeSlot; eventTypeId: number; uid: string }): Promise<any | null>;
+export interface SelectedSlotRepositoryInterface<T = any> {
+  findMany<TSelect = T>(args: FindManyArgs<TSelect>): Promise<TSelect[]>;
+  findFirst<TSelect = T>(args: { where: WhereCondition; select?: TSelect }): Promise<TSelect | null>;
+  findReservedByOthers(args: { slot: TimeSlot; eventTypeId: number; uid: string }): Promise<T | null>;

This approach maintains flexibility while preserving type safety for consumers of the interface.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/lib/server/repository/selectedSlot.ts between lines 23 and 49, the
SelectedSlotRepositoryInterface uses 'any' types extensively, which reduces type
safety. To fix this, replace 'any' with more specific types or introduce
generics to define the expected shapes of arguments and return values. This will
maintain abstraction from Prisma while ensuring compile-time type checking and
improving overall type safety for interface consumers.

Co-Authored-By: alex@cal.com <me@alexvanandel.com>
@emrysal
Copy link
Contributor Author

emrysal commented Jul 24, 2025

Pending @supalarry for info on the libraries test failure.

@emrysal emrysal marked this pull request as draft July 24, 2025 18:56
@socket-security
Copy link

socket-security bot commented Jul 25, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License

View full report

@emrysal emrysal merged commit fde1d67 into main Jul 25, 2025
66 of 70 checks passed
@emrysal emrysal deleted the devin/refactor-selected-slot-repository-1753285781 branch July 25, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants