fix(api): add 'math-sprint' to settings endpoint validation

Add 'math-sprint' to validGames array in PATCH /api/arcade/rooms/:roomId/settings

Without this change, selecting math-sprint from room page returns:
  400 Bad Request - "Invalid game name"

This is another instance of the coupling issue - hardcoded validation
array must be manually updated for each new game.

The TODO comment on line 97 acknowledges this:
  "TODO: make this dynamic when we refactor to lazy-load registry"

Addresses Issue #1 from AUDIT_2_ARCHITECTURE_QUALITY.md
This commit is contained in:
Thomas Hallock
2025-10-15 21:11:22 -05:00
parent 7b112a98ba
commit d790e5e278

View File

@@ -20,7 +20,7 @@ type RouteContext = {
* Body:
* - accessMode?: 'open' | 'locked' | 'retired' | 'password' | 'restricted' | 'approval-only'
* - password?: string (plain text, will be hashed)
* - gameName?: 'matching' | 'memory-quiz' | 'complement-race' | 'number-guesser' | null (select game for room)
* - gameName?: 'matching' | 'memory-quiz' | 'complement-race' | 'number-guesser' | 'math-sprint' | null (select game for room)
* - gameConfig?: object (game-specific settings)
*/
export async function PATCH(req: NextRequest, context: RouteContext) {
@@ -95,7 +95,7 @@ export async function PATCH(req: NextRequest, context: RouteContext) {
// Validate gameName if provided
if (body.gameName !== undefined && body.gameName !== null) {
// Legacy games + registry games (TODO: make this dynamic when we refactor to lazy-load registry)
const validGames = ['matching', 'memory-quiz', 'complement-race', 'number-guesser']
const validGames = ['matching', 'memory-quiz', 'complement-race', 'number-guesser', 'math-sprint']
if (!validGames.includes(body.gameName)) {
return NextResponse.json({ error: 'Invalid game name' }, { status: 400 })
}