Skip to content

Fix/minor tech debt#29791

Open
Ashid332 wants to merge 5 commits into
calcom:mainfrom
Ashid332:fix/minor-tech-debt
Open

Fix/minor tech debt#29791
Ashid332 wants to merge 5 commits into
calcom:mainfrom
Ashid332:fix/minor-tech-debt

Conversation

@Ashid332

Copy link
Copy Markdown

What does this PR do?

  • Fixes #XXXX (GitHub issue number)

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings
  • My PR is too large (>500 lines or >10 files) and should be split into smaller PRs

Ashid332 added 3 commits July 15, 2026 20:43
- Replaces flawed containment logic with strict interval intersection math
- Centralizes Prisma where-clause generation into prismaIntervalOverlap.ts
- Migrates getBusyTimes, BookingRepository, and HolidayRepository to new utility
- Adds comprehensive behavioral and unit test coverage for overlapping scenarios
fix: resolve busy time overlap logic and centralize interval queries
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @Ashid332! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions

Copy link
Copy Markdown
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Fix/minor tech debt". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85c8d21d-7676-4dca-9dec-74933002ee77

📥 Commits

Reviewing files that changed from the base of the PR and between 9eab07e and 41c9310.

📒 Files selected for processing (1)
  • packages/lib/prismaIntervalOverlap.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/lib/prismaIntervalOverlap.ts

📝 Walkthrough

Walkthrough

The change adds a shared Prisma interval-overlap helper with strict and inclusive boundary modes and input validation. Booking, busy-time, and holiday queries now use the helper, with tests covering overlap boundaries and helper behavior. User deletion now uses a new UserRepository.delete method instead of direct Prisma access. An obsolete username-checking TODO comment was removed.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is generic and doesn't convey the specific overlap and repository refactor changes in this PR. Use a concise title that names the main change, such as centralizing Prisma interval overlap logic.
Description check ❓ Inconclusive The description is a generic template and barely relates to the actual code changes. Replace the template text with a brief summary of the interval-overlap helper, repository updates, and tests.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/features/busyTimes/services/getBusyTimes.test.ts`:
- Around line 407-420: Update the mock filtering logic around where,
startTimeCondition, and endTimeCondition to remove the broad as any cast and use
narrow, type-safe casts for the specific where properties. Replace the Day.js
comparisons with native Date comparisons using booking.startTime/endTime and the
lt/gt values, while preserving the existing optional-condition behavior.

In `@packages/features/users/lib/deleteUser.ts`:
- Around line 9-10: Update the repository construction in the delete-user flow
to pass the module’s existing Prisma client into UserRepository. Change the
UserRepository instantiation near the delete call to use prisma, while
preserving the existing delete({ id: user.id }) behavior.

In `@packages/lib/prismaIntervalOverlap.ts`:
- Around line 31-41: Replace the generic Error throws in the date validation
checks with ErrorWithCode imported from `@calcom/lib/errors`. Update each
validation failure in the interval validation logic to use the appropriate
ErrorWithCode construction while preserving the existing messages and validation
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7367634-6f8f-4c6a-9f3a-bafc2f5f8e82

📥 Commits

Reviewing files that changed from the base of the PR and between f004349 and a822976.

📒 Files selected for processing (9)
  • packages/features/bookings/repositories/BookingRepository.ts
  • packages/features/busyTimes/services/getBusyTimes.test.ts
  • packages/features/busyTimes/services/getBusyTimes.ts
  • packages/features/holidays/repositories/HolidayRepository.ts
  • packages/features/profile/lib/checkUsername.ts
  • packages/features/users/lib/deleteUser.ts
  • packages/features/users/repositories/UserRepository.ts
  • packages/lib/prismaIntervalOverlap.test.ts
  • packages/lib/prismaIntervalOverlap.ts

Comment on lines +407 to +420
const where = args?.where as any;
const startTimeCondition = where?.startTime;
const endTimeCondition = where?.endTime;

return existingBookings.filter((booking) => {
// Emulate Prisma's lt/gt logic
const startsBeforeEnd = startTimeCondition?.lt
? dayjs(booking.startTime).isBefore(dayjs(startTimeCondition.lt))
: true;
const endsAfterStart = endTimeCondition?.gt
? dayjs(booking.endTime).isAfter(dayjs(endTimeCondition.gt))
: true;
return startsBeforeEnd && endsAfterStart;
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove as any and use native Date comparisons.

As per coding guidelines:

  • Never use as any — use proper type-safe solutions instead.
  • Use native Date instead of Day.js when timezone awareness isn't needed.

You can safely cast the specific where properties without bypassing the entire type system using any. Additionally, native Date comparisons (<, >) are more performant and idiomatic here than instantiating Day.js objects for simple before/after checks.

♻️ Proposed refactor
-        const where = args?.where as any;
-        const startTimeCondition = where?.startTime;
-        const endTimeCondition = where?.endTime;
+        const where = args?.where;
+        const startTimeCondition = where?.startTime as { lt?: Date } | undefined;
+        const endTimeCondition = where?.endTime as { gt?: Date } | undefined;
         
         return existingBookings.filter((booking) => {
           // Emulate Prisma's lt/gt logic
           const startsBeforeEnd = startTimeCondition?.lt
-            ? dayjs(booking.startTime).isBefore(dayjs(startTimeCondition.lt))
+            ? booking.startTime < startTimeCondition.lt
             : true;
           const endsAfterStart = endTimeCondition?.gt
-            ? dayjs(booking.endTime).isAfter(dayjs(endTimeCondition.gt))
+            ? booking.endTime > endTimeCondition.gt
             : true;
           return startsBeforeEnd && endsAfterStart;
         });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const where = args?.where as any;
const startTimeCondition = where?.startTime;
const endTimeCondition = where?.endTime;
return existingBookings.filter((booking) => {
// Emulate Prisma's lt/gt logic
const startsBeforeEnd = startTimeCondition?.lt
? dayjs(booking.startTime).isBefore(dayjs(startTimeCondition.lt))
: true;
const endsAfterStart = endTimeCondition?.gt
? dayjs(booking.endTime).isAfter(dayjs(endTimeCondition.gt))
: true;
return startsBeforeEnd && endsAfterStart;
});
const where = args?.where;
const startTimeCondition = where?.startTime as { lt?: Date } | undefined;
const endTimeCondition = where?.endTime as { gt?: Date } | undefined;
return existingBookings.filter((booking) => {
// Emulate Prisma's lt/gt logic
const startsBeforeEnd = startTimeCondition?.lt
? booking.startTime < startTimeCondition.lt
: true;
const endsAfterStart = endTimeCondition?.gt
? booking.endTime > endTimeCondition.gt
: true;
return startsBeforeEnd && endsAfterStart;
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/features/busyTimes/services/getBusyTimes.test.ts` around lines 407 -
420, Update the mock filtering logic around where, startTimeCondition, and
endTimeCondition to remove the broad as any cast and use narrow, type-safe casts
for the specific where properties. Replace the Day.js comparisons with native
Date comparisons using booking.startTime/endTime and the lt/gt values, while
preserving the existing optional-condition behavior.

Source: Coding guidelines

Comment thread packages/features/users/lib/deleteUser.ts Outdated
Comment thread packages/lib/prismaIntervalOverlap.ts
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.

1 participant