Skip to content

chore: slots time range validation to zod #22942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025

Conversation

emrysal
Copy link
Contributor

@emrysal emrysal commented Aug 7, 2025

What does this PR do?

Removes various instances of TRPCError, as well as handling bad input better through zod.

Note for backwards compatibility I decided:

  • Don't auto-adjust the start time into the current time if the current time > start time, this behaviour though correct feels unintuitive.
  • Right now, the start time can go beyond the end time in various modifications.

@emrysal emrysal requested a review from a team as a code owner August 7, 2025 03:10
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes refactor and enhance schema validation for scheduling functionality by introducing a new getScheduleSchemaObject with explicit date string validation and a temporal ordering check for startTime and endTime. The getScheduleSchema is now built from this object with additional transformations. The type alias TGetScheduleInputSchema is updated to infer from the new schema object. In the service utility, error handling is revised: some TRPCError exceptions are replaced with plain Error instances, and one time range validation is removed. Code formatting is improved, and some unused variables are eliminated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

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 eda328d and 0138802.

📒 Files selected for processing (2)
  • packages/trpc/server/routers/viewer/slots/types.ts (3 hunks)
  • packages/trpc/server/routers/viewer/slots/util.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts

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

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/trpc/server/routers/viewer/slots/util.ts
  • packages/trpc/server/routers/viewer/slots/types.ts
**/*.{ts,tsx}

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

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/trpc/server/routers/viewer/slots/util.ts
  • packages/trpc/server/routers/viewer/slots/types.ts
🧠 Learnings (3)
📚 Learning: in packages/app-store/office365calendar/lib/calendarservice.ts, the fetcher method in office365calen...
Learnt from: din-prajapati
PR: calcom/cal.com#21854
File: packages/app-store/office365calendar/__tests__/unit_tests/SubscriptionManager.test.ts:0-0
Timestamp: 2025-08-05T12:04:29.037Z
Learning: In packages/app-store/office365calendar/lib/CalendarService.ts, the fetcher method in Office365CalendarService class is public, not private. It was specifically changed from private to public in this PR to support proper testing and external access patterns.

Applied to files:

  • packages/trpc/server/routers/viewer/slots/util.ts
📚 Learning: in the failedbookingsbyfield component (packages/features/insights/components/failedbookingsbyfield....
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.389Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.

Applied to files:

  • packages/trpc/server/routers/viewer/slots/util.ts
  • packages/trpc/server/routers/viewer/slots/types.ts
📚 Learning: applies to **/*.{ts,tsx} : flag excessive day.js use in performance-critical code; prefer native dat...
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*.{ts,tsx} : Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js `.utc()` in hot paths like loops

Applied to files:

  • packages/trpc/server/routers/viewer/slots/types.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: Detect changes
🔇 Additional comments (7)
packages/trpc/server/routers/viewer/slots/util.ts (3)

190-191: LGTM - Appropriate error type change.

The shift from TRPCError to plain Error is correct since the Zod schema refinement now guarantees eventTypeSlug is present for dynamic bookings. The comment provides good context for this defensive coding approach.


401-406: LGTM - Improved code formatting.

The multi-line parameter formatting enhances readability for these complex function calls. The consistent formatting pattern across all getPeriodStartDatesBetween calls improves maintainability.

Also applies to: 441-446, 497-502, 602-607, 642-647


1150-1152: LGTM - Consistent error handling improvement.

The change from TRPCError to plain Error is appropriate for this runtime misconfiguration scenario. The comment clearly explains the validation purpose, and this follows the same pattern as other error handling improvements in this PR.

packages/trpc/server/routers/viewer/slots/types.ts (4)

6-6: LGTM - Effective date validation helper.

The isValidDateString function correctly uses Date.parse() to validate date strings. This approach is appropriate for the schema validation context.


8-42: LGTM - Well-structured schema object.

The extraction of getScheduleSchemaObject with explicit date string validation improves schema organization. The validation logic is sound with clear error messages, and all field definitions are properly maintained.


58-62: LGTM - Valuable temporal validation enhancement.

The new refinement properly validates that endTime is after startTime using timestamp comparison. The error message is clear and the path specification correctly identifies the problematic field. This addresses the PR objective of improving validation.


94-94: LGTM - Improved type inference.

The change to infer TGetScheduleInputSchema from getScheduleSchemaObject is correct, providing better type safety for raw input validation while maintaining the transformed schema separately.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/slots-time-range-validation-to-zod

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
🪧 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? Create a ticket on our support page 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 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.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

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 "Chore/slots time range validation to zod". 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

@emrysal emrysal changed the title Chore/slots time range validation to zod vhore: slots time range validation to zod Aug 7, 2025
@emrysal emrysal changed the title vhore: slots time range validation to zod chore: slots time range validation to zod Aug 7, 2025
@keithwillcode keithwillcode added core area: core, team members only foundation labels Aug 7, 2025
@dosubot dosubot bot added the 🧹 Improvements Improvements to existing features. Mostly UX/UI label Aug 7, 2025
Copy link
Contributor

github-actions bot commented Aug 7, 2025

E2E results are ready!

@emrysal emrysal enabled auto-merge (squash) August 7, 2025 04:36
@emrysal emrysal merged commit cabd459 into main Aug 7, 2025
100 of 107 checks passed
@emrysal emrysal deleted the chore/slots-time-range-validation-to-zod branch August 7, 2025 12:46
Pallava-Joshi pushed a commit to Pallava-Joshi/cal.com that referenced this pull request Aug 8, 2025
* chore: Move date range validation to zod, removing TRPCError

* This is not a BAD_REQUEST but an internal error, should not happen

* Add a check to ensure the given start time is before end time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only foundation 🧹 Improvements Improvements to existing features. Mostly UX/UI ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants