Skip to content

Comments

feat: booking-delete-service-with-audit-log#23501

Closed
hemantmm wants to merge 12 commits intocalcom:mainfrom
hemantmm:booking-delete-service
Closed

feat: booking-delete-service-with-audit-log#23501
hemantmm wants to merge 12 commits intocalcom:mainfrom
hemantmm:booking-delete-service

Conversation

@hemantmm
Copy link
Contributor

@hemantmm hemantmm commented Sep 1, 2025

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)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /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

@hemantmm hemantmm requested a review from a team as a code owner September 1, 2025 17:42
@vercel
Copy link

vercel bot commented Sep 1, 2025

@hemantmm is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adds 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

Objective Addressed Explanation
Implement BookingDeleteService with audit log integration, including deletion-specific context fields and usage in cancellation flows ([#22833], [CAL-6182])

Assessment against linked issues: Out-of-scope changes

(no out-of-scope functional code changes detected)

Possibly related PRs


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between d0d22d1 and 4d27299.

📒 Files selected for processing (1)
  • packages/features/bookings/lib/handleCancelBooking.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/features/bookings/lib/handleCancelBooking.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 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/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Sep 1, 2025
@graphite-app graphite-app bot requested a review from a team September 1, 2025 17:42
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 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:

Unknown release type "feature" found in pull request title "feature: booking-delete-service-with-audit-log". 

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

@github-actions github-actions bot added bookings area: bookings, availability, timezones, double booking enterprise area: enterprise, audit log, organisation, SAML, SSO High priority Created by Linear-GitHub Sync ✨ feature New feature or request labels Sep 1, 2025
@hemantmm hemantmm changed the title feature: booking-delete-service-with-audit-log feat: booking-delete-service-with-audit-log Sep 1, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 select to 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 17ef0dc and dce3233.

📒 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 use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/bookings/lib/handleSeats/lib/lastAttendeeDeleteBooking.ts
  • packages/features/bookings/lib/BookingDeleteService.ts
  • packages/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.ts
  • packages/features/bookings/lib/BookingDeleteService.ts
  • packages/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.ts
  • packages/features/bookings/lib/BookingDeleteService.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
**/*Service.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Service files must include Service suffix, 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.

@kart1ka
Copy link
Contributor

kart1ka commented Sep 1, 2025

@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.

@kart1ka kart1ka marked this pull request as draft September 1, 2025 18:00
@hemantmm hemantmm marked this pull request as ready for review September 2, 2025 14:49
@hemantmm
Copy link
Contributor Author

hemantmm commented Sep 2, 2025

Hey @kart1ka, I have resolved the failing test and type checks.

Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

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

Left a comment. Can you please attach a loom video of this change showing that this change works?

Comment on lines +43 to +51
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
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not use any here. There is no such model as auditlog in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But as mentioned in the issue we should ensure that an auditlog entry is created for the deletion

Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

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

Left a comment. Can you please attach a loom video of this change showing that this change works?

@kart1ka kart1ka marked this pull request as draft September 2, 2025 15:58
@hemantmm
Copy link
Contributor Author

hemantmm commented Sep 3, 2025

Hey @kart1ka, here is the test passing with the changes.
image

@hemantmm hemantmm marked this pull request as ready for review September 4, 2025 13:28
@hemantmm hemantmm requested a review from kart1ka September 4, 2025 13:28
@kart1ka kart1ka marked this pull request as draft September 4, 2025 15:22
@kart1ka
Copy link
Contributor

kart1ka commented Sep 4, 2025

Hey @kart1ka, here is the test passing with the changes. image

@hemantmm We can not extract anything of value from this screenshot. Can you please attach a loom that shows the booking delete service working properly (bookings being deleted) and the logs being created?

@hemantmm
Copy link
Contributor Author

hemantmm commented Sep 4, 2025

Hey @kart1ka, here is the test passing with the changes. image

@hemantmm We can not extract anything of value from this screenshot. Can you please attach a loom that shows the booking delete service working properly (bookings being deleted) and the logs being created?

@kart1ka, here is the attached video:

Screen.Recording.2025-09-04.at.22.51.45.mov

@hemantmm hemantmm marked this pull request as ready for review September 4, 2025 17:24
@kart1ka kart1ka marked this pull request as draft September 5, 2025 04:41
@hemantmm hemantmm marked this pull request as ready for review September 5, 2025 12:12
@kart1ka
Copy link
Contributor

kart1ka commented Sep 5, 2025

Hi @hemantmm, Thank you for the PR.
Currently we have this in the works (#22817) which takes care of the BookingAudit schema and services.
The issue you're working on for this PR actually expects the booking audit pr to be merged. The BookingAudit PR itself needs to wait for Prisma Migration as we want to use UUIDV7, so for now we need to close this PR.
I want to apologize for the lack of clarity here leading to you working on this issue, but we really appreciate your efforts. 🙏

@kart1ka kart1ka closed this Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bookings area: bookings, availability, timezones, double booking community Created by Linear-GitHub Sync enterprise area: enterprise, audit log, organisation, SAML, SSO ✨ feature New feature or request High priority Created by Linear-GitHub Sync size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement BookingDeleteService with audit log integration

2 participants