fix(events): prevent duplicate participation in participateEvent#285
Merged
omkarhole merged 1 commit intoJun 3, 2026
Merged
Conversation
Fixes omkarhole#278 participateEvent pushed a new commit entry unconditionally without checking whether the user had already participated. Calling the endpoint multiple times with the same userId and eventId created duplicate entries in event.commits, inflating the participant count shown to organisers. Added a check using Array.prototype.some before the push. If the user's ID is already in event.commits the function throws an error with statusCode 409, which the global error middleware in error.middleware.js picks up and returns as HTTP 409 Conflict. The checkParticipation function was already present in the service for read-only queries, so no new database round-trip pattern is introduced.
|
@anshul23102 is attempting to deploy a commit to the omkarhole's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #278
Problem
participateEventineventService.jspushed a commit entry unconditionally:Calling the endpoint multiple times with the same
userIdandeventIdcreated duplicate entries inevent.commits, inflating the displayed participant count for organisers.Fix
Added an idempotency guard before the push:
The thrown error carries
statusCode = 409. The global error handler inerror.middleware.jsreadserr.statusCode(line 22) and forwards it as the HTTP status, so the endpoint returns 409 Conflict on duplicate attempts without any changes to the middleware.Files Changed
backend/services/eventService.jsevent.commits.pushTesting
Could you please add appropriate labels to this PR? It would help with tracking. Thank you!