Skip to content

fix: remove duplicate merged code in registerForEvent and cancelRegistration#299

Open
Subha12125 wants to merge 2 commits into
anubhavxdev:mainfrom
Subha12125:fix/registration-controller-logic
Open

fix: remove duplicate merged code in registerForEvent and cancelRegistration#299
Subha12125 wants to merge 2 commits into
anubhavxdev:mainfrom
Subha12125:fix/registration-controller-logic

Conversation

@Subha12125
Copy link
Copy Markdown

Closes #281

This PR removes mistakenly merged duplicate code from both registerForEvent and cancelRegistration, ensuring that only the correct, atomic logic remains and that event registration and cancellation workflows are reliable and safe for high-concurrency usage.

Changes Made

  • Removed the broken first implementation in registerForEvent that used manual capacity checks, which could cause race conditions.
  • Cleaned up unclosed or dangling else blocks and brackets that previously caused runtime errors and broken control flow.
  • Retained only the atomic findOneAndUpdate implementation for capacity validation, providing robust handling of simultaneous requests.
  • Fixed cancelRegistration logic, correcting the duplicate conflict and properly defining variables like eventDate.
  • Restored the waitlist promotion logic so vacancies are refilled automatically when spots open up after cancellation.

Why These Changes Were Needed

Previously, two versions of the registration logic were merged together, resulting in unreachable code, errors in registration/cancellation, and reliability issues when multiple users tried to register at the same time. Cancellation was also broken due to missing variable definitions.

How It Was Fixed

  • Deleted approximately 180 lines of redundant, buggy code, keeping only the atomic version.
  • Prevented race conditions and handled duplicate registration errors gracefully (e.g., MongoDB error 11000).
  • Triggered real-time dashboard updates using emitRegistrationCount().
  • Ensured cancelled registrations are properly reused, preserving audit trails and avoiding database conflicts.

How to Test

  1. Start the backend server using npm run dev.
  2. Run a syntax check: node --check src/controllers/registrationController.js (no errors should appear).
  3. Set an event capacity to 1, register a user, then attempt to register a second—the second should get "Event is full".
  4. Cancel a registration and confirm that the event’s registeredCount is decremented in the database.

Note:
Stage 1 may report a warning about use of a deprecated version of actions/github-script@v7 in the repo workflow, but this is unrelated to this PR’s changes.


This version:

Next:
Update your pull request description and title as shown above—these changes will make the automated validation pass, assuming the PR is based on a feature branch and the linked issue (#281) is open and assigned to you.

Copilot AI review requested due to automatic review settings May 23, 2026 19:46
@github-actions
Copy link
Copy Markdown

👋 Thanks for opening a PR, @Subha12125!

Your PR has entered the 🎯 EventOne GSSoC PR Review Pipeline.

🟢 GSSoC PR detected — your PR will be routed to an approved GSSoC mentor for Stage 2 review.

What happens next

Stage Reviewer Checks
Stage 1 — Automated Validation 🤖 Bot Title format · Issue link · AI Slop · Branch check
Stage 2 — Mentor Review 🧑‍🏫 GSSoC Mentor Code + Quality Review
Stage 3 — Admin Final Gate 🔑 @anubhavxdev Label check + Final Merge Decision

A pipeline status comment will appear below and update automatically as your PR progresses.


While you wait

  • Sign all commits using git commit -s
  • Link your issue with Closes #123
  • Use a feature branch — not main
  • Avoid unrelated changes in the same PR
  • Write your own description — no AI-generated content

This comment is posted only once.

EventOne × GSSoC Automated Pipeline

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 23, 2026

❌ PR Format Check — Failed — Please Fix Below

Hi @Subha12125! Please fix the issues below before your PR can proceed to mentor review.

❌ Must Fix Before Proceeding

Issue #281 is not assigned to you (@Subha12125) — You must be assigned to the issue before submitting a PR.

Comment /assign on Issue #281 or ask a maintainer to assign it to you.

Issue #281 is not assigned to you (@Subha12125) — You must be assigned to the issue before submitting a PR.

Comment /assign on Issue #281 or ask a maintainer to assign it to you.


📋 EventOne PR Guidelines (click to expand)

Title format — Conventional Commits:
feat: · fix: · docs: · style: · refactor: · test: · chore: · perf:

Always link an issue: Closes #number

Use a feature branch — never PR directly from main

Write your own description — AI-generated content = gssoc:ai-slop label

EventOne × GSSoC Pipeline — Stage 1 Automated Check

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors event registration and cancellation flows in registrationController to reduce duplication, improve consistency, and add clearer handling around capacity, refunds, and notifications.

Changes:

  • Simplified registerForEvent with a single flow for QR generation, duplicate handling, live stats emission, and email sending.
  • Hardened cancelRegistration with existence checks, past-event cancellation prevention, refund-policy handling, and waitlist promotion.
  • Standardized formatting and logging/error messaging across the controller.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/src/controllers/registrationController.js
Comment thread backend/src/controllers/registrationController.js
Comment thread backend/src/controllers/registrationController.js
Comment on lines +116 to +125
// Send email (non-blocking)
try {
await sendEmail({
to: req.user.email,
subject: `Registered: ${event.title}`,
html: `<p>You are registered for ${event.title}.</p>`,
});
} catch (_) {}
} catch (_) {
// Ignore email errors to not break registration flow
}
Comment thread backend/src/controllers/registrationController.js
@Subha12125 Subha12125 force-pushed the fix/registration-controller-logic branch from 62e5d3d to 52eae7f Compare May 23, 2026 19:49
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

@Subha12125 is attempting to deploy a commit to the anubhav12302387's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Collaborator

@Nitya-003 Nitya-003 left a comment

Choose a reason for hiding this comment

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

@anubhavxdev Resolved the conflicts. Merge it.

@Subha12125
Copy link
Copy Markdown
Author

@anubhavxdev I raised the PR , so why you assigned to others ????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bug: registerForEvent function has duplicate/merged code blocks with broken control flow

4 participants