[P0] Lock down race mutations to participants and valid states - #2
Open
anshgupta2000 wants to merge 1 commit into
Open
[P0] Lock down race mutations to participants and valid states#2anshgupta2000 wants to merge 1 commit into
anshgupta2000 wants to merge 1 commit into
Conversation
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.
Motivation
challenger_id === userId || opponent_id === userIdcan perform race actions.accept,decline,forfeit, andupdate_distancecould be applied by outsiders or in invalid race states.Description
isParticipant(race, userId)immediately after race lookup and return403for outsiders.race.statusisfinishedordeclinedand returns409with an explanatory message.accept/declineto the opponent and topendingraces, and requireactivestatus forupdate_distanceandforfeit.forfeithandling that marks the racefinished, assignswinner_id/loser_id, updatesauth_userswins/losses, and returns the finalized race; and add focused route tests indruta/apps/web/src/app/api/races/route.test.tscovering outsider attempts, finished-race updates, and a valid participant distance update.Testing
druta/apps/web/src/app/api/races/route.test.tsthat mocksql,auth, andensureAuthUserand cover outsider mutation, finished-race rejection, and a successful participant update.cd druta/apps/web && npm test -- --run src/app/api/races/route.test.ts, which failed due to notestscript inpackage.json.cd druta/apps/web && npx vitest run src/app/api/races/route.test.ts, which failed in this environment due to localvitestdependency/config resolution issues.Codex Task