refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository#22705
refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository#22705
Conversation
- 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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
WalkthroughThis change set systematically refactors the codebase to rename the repository handling selected slots from the plural form ( Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes
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
apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.tsOops! 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: 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 detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…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>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
…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>
There was a problem hiding this comment.
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 consistencyThe class has been renamed to
SelectedSlotRepositoryFixture, but the file path remainsselected-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 / deleteByUIdappear 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 pathSame 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
findManyReservedByOthersmethod changed from using the internalfindManymethod to directly callingthis.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
findManymethod 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
📒 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.tsapps/api/v2/src/lib/modules/available-slots.module.tsapps/api/v2/test/fixtures/repository/selected-slots.repository.fixture.tspackages/platform/libraries/repositories.tspackages/lib/di/modules/available-slots.tspackages/trpc/server/routers/viewer/slots/reserveSlot.handler.test.tsapps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.tspackages/trpc/server/routers/viewer/slots/reserveSlot.handler.tspackages/trpc/server/routers/viewer/slots/isAvailable.handler.tsapps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.tspackages/lib/di/modules/selectedSlots.tsapps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.tsapps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/team-event-type-slots.controller.e2e-spec.tsapps/api/v2/src/lib/services/available-slots.service.tspackages/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
PrismaSelectedSlotsRepositorytoPrismaSelectedSlotRepository, 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
SelectedSlotsRepositoryFixturetoSelectedSlotRepositoryFixture, 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
PrismaSelectedSlotRepositorywhile 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
SelectedSlotsRepositorytoPrismaSelectedSlotRepository. 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
SelectedSlotsRepositorytoPrismaSelectedSlotRepository. 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
PrismaSelectedSlotsRepositorytoPrismaSelectedSlotRepositoryto follow singular naming convention.
4-4: No action required onPrismaSelectedSlotsRepositoryimportVerified that
packages/platform/libraries/repositories.tsexports the class as:export { PrismaSelectedSlotRepository as PrismaSelectedSlotsRepository }and the import in
apps/api/v2/src/lib/repositories/prismaSelectedSlotRepository.tscorrectly 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
SelectedSlotsRepositoryFixturetoSelectedSlotRepositoryFixture.
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:selectedSlotRepoconsistencyVerified that the
IAvailableSlotsServiceinterface in
packages/trpc/server/routers/viewer/slots/util.tsdefines
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
SelectedSlotRepositoryinstead ofSelectedSlotsRepository.
16-16: LGTM: Mock class name updated correctly.The mock implementation has been properly updated to use
PrismaSelectedSlotRepositorywhile 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
PrismaSelectedSlotRepositorywhile maintaining backward compatibility by exporting it asPrismaSelectedSlotsRepository. 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 impactVariable 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 aboveOnce 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
PrismaSelectedSlotRepositoryand correctly implements the new interface.
95-98: Good practice: Selecting only required fields.The Prisma queries correctly use
selectto fetch only the necessary fields, which improves performance and follows the established best practices.Also applies to: 114-122
apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.e2e-spec.ts
Outdated
Show resolved
Hide resolved
.../modules/slots/slots-2024-09-04/controllers/e2e/team-event-type-slots.controller.e2e-spec.ts
Outdated
Show resolved
Hide resolved
| OR?: WhereCondition[]; | ||
| }; | ||
| select?: Prisma.SelectedSlotsSelect; | ||
| select?: any; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
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>
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (3)
packages/lib/server/repository/selectedSlot.ts (3)
11-16: Consider using generics instead ofanyfor better type safety.The change from a Prisma-specific type to
anyreduces 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 internalfindManymethod.The method bypasses the internal
findManymethod 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
📒 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
PrismaSelectedSlotRepositoryclearly indicates this is a Prisma-specific implementation and follows better naming conventions.
| 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 }>; | ||
| } |
There was a problem hiding this comment.
🛠️ 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>
|
Pending @supalarry for info on the libraries test failure. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository
Summary
This PR refactors the
SelectedSlotsRepositoryclass toPrismaSelectedSlotRepositoryfor 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:
SelectedSlotsRepository→PrismaSelectedSlotRepositoryin the main class definitionselectedSlotsRepo→selectedSlotRepofor consistencyReview & Testing Checklist for Human
apps/api/v2/src/modules/slots/yarn type-check:cito ensure no type errors were introducedRecommended 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:#FFFFFFNotes
yarn type-check:cireturning successpackages/platform/libraries/repositories.tsSession Info: