feat: booking-delete-service-with-audit-log#23501
feat: booking-delete-service-with-audit-log#23501hemantmm wants to merge 12 commits intocalcom:mainfrom
Conversation
|
@hemantmm is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdds packages/features/bookings/lib/BookingDeleteService.ts exporting BookingDeleteService.deleteBooking which updates a booking's status to CANCELLED via Prisma, builds an audit context (type "record_deleted", wasRescheduled, totalUpdates, actor, additionalContext), and conditionally creates an audit log entry within the Prisma transaction if an auditlog model exists. Integrates this service into handleCancelBooking and handleSeats/lib/lastAttendeeDeleteBooking to invoke deleteBooking after status updates and integration deletions. The method returns the updated booking (id selected). Assessment against linked issues
Assessment against linked issues: Out-of-scope changes(no out-of-scope functional code changes detected) Possibly related PRs
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
|
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: |
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.ts (1)
60-67: Select minimal fields on update (Prisma guideline).You don’t use the updated record; restrict the payload.
await prisma.booking.update({ where: { id: originalRescheduledBooking.id, }, data: { status: BookingStatus.CANCELLED, }, + select: { id: true }, });
🧹 Nitpick comments (2)
packages/features/bookings/lib/BookingDeleteService.ts (2)
12-24: Tighten types for actor and context.Use a discriminated union for actor to avoid invalid shapes and ease downstream inference.
Type suggestion (outside diff):
type SystemActor = { type: "system" }; type UserActor = { type: "user"; id: number; email?: string }; type Actor = SystemActor | UserActor; type AuditLogContext = { type: "record_deleted"; wasRescheduled?: boolean; totalUpdates?: number; actor: Actor; } & Record<string, unknown>;
49-50: Don’t return the whole booking if unused.The callers don’t use the return value. Return void to avoid unnecessary data retrieval and to discourage misuse.
- return booking; + return;If you keep a return, ensure the preceding update uses
selectto minimize payload (see earlier comment).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
packages/features/bookings/lib/BookingDeleteService.ts(1 hunks)packages/features/bookings/lib/handleCancelBooking.ts(2 hunks)packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.tspackages/features/bookings/lib/BookingDeleteService.tspackages/features/bookings/lib/handleCancelBooking.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/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.tspackages/features/bookings/lib/BookingDeleteService.tspackages/features/bookings/lib/handleCancelBooking.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.tspackages/features/bookings/lib/BookingDeleteService.tspackages/features/bookings/lib/handleCancelBooking.ts
**/*Service.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Service files must include
Servicesuffix, use PascalCase matching exported class, and avoid generic names (e.g.,MembershipService.ts)
Files:
packages/features/bookings/lib/BookingDeleteService.ts
🧬 Code graph analysis (1)
packages/features/bookings/lib/handleCancelBooking.ts (1)
packages/features/bookings/lib/BookingDeleteService.ts (1)
BookingDeleteService(11-51)
🔇 Additional comments (3)
packages/features/bookings/lib/BookingDeleteService.ts (1)
25-30: Remove duplicate status update
Both handleCancelBooking and lastAttendeeDeleteBooking already set status="CANCELLED" before invoking BookingDeleteService.deleteBooking(), which then issues a second prisma.booking.update. Choose one approach:
- Let the service own cancellation (move iCalSequence/cancellationReason/cancelledBy here and stop updating status in callers), or
- Make this service audit‐only and drop the status update (and its return value).
packages/features/bookings/lib/handleCancelBooking.ts (1)
40-40: Import looks good.packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.ts (1)
12-12: Import looks good.
packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.ts
Outdated
Show resolved
Hide resolved
|
@hemantmm Thanks for the pr. Tests and type checks seem to be failing. Pls fix them. Can you also address coderabbit suggestions if applicable. Making it draft until them. Feel free to rfr once the comments are addressed. |
|
Hey @kart1ka, I have resolved the failing test and type checks. |
kart1ka
left a comment
There was a problem hiding this comment.
Left a comment. Can you please attach a loom video of this change showing that this change works?
| await prisma.$transaction(async (tx) => { | ||
| // Only attempt auditlog if it exists (skip in test envs like Prismock) | ||
| if ((tx as any).auditlog && typeof (tx as any).auditlog.create === "function") { | ||
| await (tx as any).auditlog.create({ | ||
| data: { entity: "booking", entityId: bookingId, action: "delete", context }, | ||
| }); | ||
| } | ||
| // else: skip audit log in test/mock environments | ||
| }); |
There was a problem hiding this comment.
We should not use any here. There is no such model as auditlog in the codebase.
There was a problem hiding this comment.
But as mentioned in the issue we should ensure that an auditlog entry is created for the deletion
kart1ka
left a comment
There was a problem hiding this comment.
Left a comment. Can you please attach a loom video of this change showing that this change works?
|
Hey @kart1ka, here is the test passing with the changes. |
@kart1ka, here is the attached video: Screen.Recording.2025-09-04.at.22.51.45.mov |
|
Hi @hemantmm, Thank you for the PR. |


closes: #22833
What does this PR do?
Visual Demo (For contributors especially)
N/A
Video Demo (if applicable):
N/A
Image Demo (if applicable):
N/A
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist