Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

refactor: convert getBusyTimes to service class with dependency injection

Summary

This PR refactors the packages/lib/getBusyTimes.ts file from standalone functions to a service class using dependency injection, following the same pattern as UserAvailabilityService. The refactoring includes:

  • Created BusyTimesService class with dependency injection for BookingRepository
  • Added DI infrastructure with new tokens, modules, and containers
  • Updated all usage locations across the codebase to use the new service instead of direct function calls
  • Maintained backward compatibility with legacy exports that route through the new service
  • Fixed linting issues by making legacy exports async with proper dynamic imports

The main functions (getBusyTimes, getBusyTimesForLimitChecks, getStartEndDateforLimitCheck) are now methods on the service class, with the same signatures and behavior preserved.

Review & Testing Checklist for Human

  • End-to-end booking flow testing - Verify that creating bookings, checking availability, and slot generation all work correctly (highest priority - this touches core user flows)
  • Legacy function compatibility - Test that any remaining direct imports of getBusyTimes, getBusyTimesForLimitChecks, or getStartEndDateforLimitCheck still work
  • Async compatibility verification - Confirm that making getStartEndDateforLimitCheck async doesn't break any calling code that expected synchronous behavior
  • DI container functionality - Verify the service is properly instantiated with correct dependencies by testing a booking scenario locally
  • Performance impact check - Monitor for any performance regressions due to dynamic imports and service instantiation

Recommended test plan: Create a test booking through the UI, verify availability slots are shown correctly, and confirm busy times are properly calculated during the booking process.


Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    subgraph "DI Infrastructure"
        tokens["packages/lib/di/tokens.ts"]:::minor-edit
        module["packages/lib/di/modules/busy-times.ts"]:::major-edit
        container["packages/lib/di/containers/busy-times.ts"]:::major-edit
    end
    
    subgraph "Core Service"
        getBusyTimes["packages/lib/getBusyTimes.ts<br/>BusyTimesService class"]:::major-edit
        bookingRepo["BookingRepository"]:::context
    end
    
    subgraph "Usage Locations"
        userAvail["packages/lib/getUserAvailability.ts"]:::minor-edit
        slotsUtil["packages/trpc/server/routers/viewer/slots/util.ts"]:::minor-edit
        ensureUsers["packages/features/bookings/lib/handleNewBooking/ensureAvailableUsers.ts"]:::minor-edit
        limitsServer["packages/lib/intervalLimits/server/getBusyTimesFromLimits.ts"]:::minor-edit
    end
    
    container --> getBusyTimes
    module --> container
    tokens --> module
    getBusyTimes --> bookingRepo
    
    userAvail --> container
    slotsUtil --> container
    ensureUsers --> container
    limitsServer --> container
    
    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

  • This refactoring follows the exact same dependency injection pattern as UserAvailabilityService for consistency
  • Legacy exports are maintained to ensure smooth transition, but they now route through the new service
  • The getStartEndDateforLimitCheck function was made async to resolve ESLint linting issues with require statements
  • All existing tests pass and type checking succeeds
  • Session requested by: morgan@cal.com via Slack #talk-to-devin
  • Devin session: https://app.devin.ai/sessions/da6c2d785fd740d39aa1b3a9133d5f37

…tion

- Create BusyTimesService following UserAvailabilityService pattern
- Add DI tokens, module, and container setup for BusyTimesService
- Update all usage locations to use service instead of direct function calls
- Maintain existing function signatures for backward compatibility
- Add legacy exports to ensure smooth transition
- Update type references in trpc util to use service prototype
- Fix linting issues by making legacy exports async with proper imports
- All tests pass and type checking succeeds

Co-Authored-By: morgan@cal.com <morgan@cal.com>
Copy link
Contributor Author

🤖 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

Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 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.
  • 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.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in 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.

Copy link

vercel bot commented Aug 7, 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) Aug 8, 2025 8:01am
cal-eu ⬜️ Ignored (Inspect) Aug 8, 2025 8:01am

@ThyMinimalDev ThyMinimalDev marked this pull request as ready for review August 8, 2025 07:42
@ThyMinimalDev ThyMinimalDev requested review from a team as code owners August 8, 2025 07:42
@graphite-app graphite-app bot requested a review from a team August 8, 2025 07:42
@dosubot dosubot bot added platform Anything related to our platform plan 💻 refactor labels Aug 8, 2025
Copy link

graphite-app bot commented Aug 8, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (08/08/25)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

github-actions bot commented Aug 8, 2025

E2E results are ready!

@ThyMinimalDev ThyMinimalDev merged commit 29314cd into main Aug 8, 2025
61 of 64 checks passed
@ThyMinimalDev ThyMinimalDev deleted the devin/refactor-busy-times-service-1754554102 branch August 8, 2025 09:14
Pallava-Joshi pushed a commit to Pallava-Joshi/cal.com that referenced this pull request Aug 8, 2025
…tion (calcom#22949)

* refactor: convert getBusyTimes to service class with dependency injection

- Create BusyTimesService following UserAvailabilityService pattern
- Add DI tokens, module, and container setup for BusyTimesService
- Update all usage locations to use service instead of direct function calls
- Maintain existing function signatures for backward compatibility
- Add legacy exports to ensure smooth transition
- Update type references in trpc util to use service prototype
- Fix linting issues by making legacy exports async with proper imports
- All tests pass and type checking succeeds

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* refactor: busy time service

* fix: api v2 eslint plugins version mismatch

* chore: bump platform libs

* chore: bump platform libs

* fix: missing di busyTimesModule in slots service

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: morgan@cal.com <morgan@cal.com>
Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform Anything related to our platform plan ready-for-e2e 💻 refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant