feat(api): add answer evaluation endpoint

Complete the game answer flow:

- Add evaluateAnswer service function: looks up the session in the
  GameSessionStore, compares the submitted optionId against the stored
  correct answer, returns an AnswerResult.
- Add submitAnswer controller with safeParse validation and error
  handling (session/question not found → 404).
- Add POST /api/v1/game/answer route.
- Fix createGameSession: was missing the answerKey tracking and the
  gameSessionStore.create() call, so sessions were never persisted.

The full singleplayer game loop now works end-to-end:
POST /game/start → GameSession, POST /game/answer → AnswerResult.
This commit is contained in:
lila 2026-04-11 12:12:54 +02:00
parent 0755c57439
commit 075a691849
4 changed files with 83 additions and 9 deletions

View file

@ -1,7 +1,8 @@
import express from "express";
import type { Router } from "express";
import { createGame } from "../controllers/gameController.js";
import { createGame, submitAnswer } from "../controllers/gameController.js";
export const gameRouter: Router = express.Router();
gameRouter.post("/start", createGame);
gameRouter.post("/answer", submitAnswer);