Prevent Duplicate Event Registrations#133
Conversation
|
@AYUSH-P-SINGH is attempting to deploy a commit to the niharika-mente's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAdds a ChangesEvent Registration API and Booking Duplicate Guard
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@app/api/events/`[id]/register/route.ts:
- Around line 13-109: The new POST registration route violates the repo pattern
and duplicates logic already handled by createBooking. Remove the
app/api/events/[id]/register route handler and move its validation and booking
flow into the existing createBooking server action in lib/actions/*.actions.ts,
including event lookup, email validation, duplicate checking, Booking.create,
and revalidatePath. Then update the client to call createBooking directly so
there is a single booking path and no divergent API route.
- Line 94: The catch in the route handler currently uses `error: any`, which
should be avoided; update the `register` route’s `catch` block to use `unknown`
instead, then narrow the value before accessing `.code` just like the server
action does. Keep the handling logic in the same `route.ts` handler, but add the
appropriate type guard or `instanceof`/property check so only narrowed errors
are read for `.code`.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 87d28dfb-1c4c-4a0e-a026-92356ef7cca3
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json,!package-lock.json
📒 Files selected for processing (3)
app/api/events/[id]/register/route.tslib/actions/booking.actions.tstsconfig.json
TarunyaProgrammer
left a comment
There was a problem hiding this comment.
LGTM! The defensive checks in the server action and the new registration API endpoint are very clean and well-structured. Thanks for handling the path revalidation and edge cases (like the unique index constraints) properly! 🚀
Closes issue #129
Description
This PR prevents duplicate event registrations by ensuring a user cannot register for the same event more than once using the same email address.
Changes made:
POST /api/events/[id]/registerAPI endpoint.trim().toLowerCase().lib/actions/booking.actions.tsto maintain consistent duplicate-check logic.11000) errors gracefully.Fixes #
Type of Change
How Has This Been Tested?
Manual testing
Registered a new email for an event successfully.
Attempted to register the same email again for the same event and verified that a 409 Conflict response was returned.
Verified that the same email can register for different events.
Verified email matching is case-insensitive (
User@example.comanduser@example.comare treated as the same).Confirmed the project compiles without TypeScript errors.
Checklist
Summary by CodeRabbit
New Features
Bug Fixes