Skip to content

Prevent Duplicate Event Registrations#133

Merged
TarunyaProgrammer merged 3 commits into
niharika-mente:mainfrom
AYUSH-P-SINGH:prevent-duplicat-event
Jul 1, 2026
Merged

Prevent Duplicate Event Registrations#133
TarunyaProgrammer merged 3 commits into
niharika-mente:mainfrom
AYUSH-P-SINGH:prevent-duplicat-event

Conversation

@AYUSH-P-SINGH

@AYUSH-P-SINGH AYUSH-P-SINGH commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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:

  • Added a new POST /api/events/[id]/register API endpoint.
  • Validates event ID, request body, email format, and event existence.
  • Normalizes email addresses using trim().toLowerCase().
  • Checks for existing registrations before creating a new booking.
  • Returns 409 Conflict for duplicate registration attempts.
  • Updated lib/actions/booking.actions.ts to maintain consistent duplicate-check logic.
  • Handles MongoDB duplicate key (11000) errors gracefully.
  • Revalidates relevant pages after successful registration.

Fixes #


Type of Change

  • Bug fix (non-breaking change which fixes an issue)

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.com and user@example.com are treated as the same).

  • Confirmed the project compiles without TypeScript errors.


Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings or console errors.

Summary by CodeRabbit

  • New Features

    • Added event registration support so users can submit an email to book an event.
  • Bug Fixes

    • Improved duplicate booking handling to prevent the same email from registering for the same event twice.
    • Added clearer responses for invalid requests, missing events, and duplicate registrations.
    • Updated page refresh behavior so event and home pages stay in sync after a successful booking.

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a POST REST endpoint at app/api/events/[id]/register/route.ts that validates the event ID and email, checks for duplicates, creates a booking, and revalidates cache. Updates createBooking in lib/actions/booking.actions.ts to proactively guard against duplicate bookings via an explicit pre-insert query.

Changes

Event Registration API and Booking Duplicate Guard

Layer / File(s) Summary
createBooking duplicate guard
lib/actions/booking.actions.ts
createBooking now queries for an existing Booking by eventId + normalized email before attempting insert, returning an early error; other functions (getBookingsByEventId, getBookingsCountByEventId, getBookingsByEmail) have formatting-only changes.
POST registration route
app/api/events/[id]/register/route.ts
Adds the complete POST handler: validates id as ObjectId and email via regex, connects to DB, checks event existence, detects duplicate registrations, creates the booking, revalidates /events/${slug} and / paths, and returns structured JSON with status codes 201/400/404/409/500.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preventing duplicate event registrations.
Description check ✅ Passed The description covers the required summary, issue reference, change type, testing, and checklist well enough.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8049abd and 5be8274.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !package-lock.json
📒 Files selected for processing (3)
  • app/api/events/[id]/register/route.ts
  • lib/actions/booking.actions.ts
  • tsconfig.json

Comment thread app/api/events/[id]/register/route.ts
Comment thread app/api/events/[id]/register/route.ts

@TarunyaProgrammer TarunyaProgrammer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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! 🚀

@TarunyaProgrammer TarunyaProgrammer merged commit b75bb66 into niharika-mente:main Jul 1, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Medium SSoC26 TO CONTRIBUTE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants