Premier League Predictor: Astro — Chapter 6, Exercise 3 ==================================================== TASK Enter an incorrect result for a fixture with at least two recorded predictions, confirm both predictions' points_awarded values, then call PATCH /api/fixtures/{id}/result again with the corrected result and confirm that every prediction's points_awarded actually changes to reflect the correction — not just predictions added after the fix. SOLUTION Steps to complete the hands-on part: 1. Using fixture 42 from the chapter's own worked example (with the user's 2-1, the expert's 1-1, and the ai's 2-0 predictions already recorded), first enter a deliberately wrong result: PATCH /api/fixtures/42/result { "home_score": 1, "away_score": 1 } This makes 1-1 the "actual" result, so the response for GET /api/fixtures/42 (joined with its predictions) shows: - user (predicted 2-1): outcome(2,1) = HOME_WIN, actual outcome DRAW -> neither matches -> points_awarded = 0 - expert (predicted 1-1): exact match -> points_awarded = 40 2. Confirm those two values directly, e.g. via SELECT source, predicted_home_score, predicted_away_score, points_awarded FROM predictions WHERE fixture_id = 42; which should show user at 0 and expert at 40. 3. Now call PATCH /api/fixtures/42/result again with the real, corrected result: PATCH /api/fixtures/42/result { "home_score": 2, "away_score": 1 } 4. Re-run the same SELECT. Both rows should have changed: - user (predicted 2-1): exact match against the corrected 2-1 -> points_awarded = 40 (up from 0) - expert (predicted 1-1): outcome(1,1) = DRAW, corrected actual outcome HOME_WIN -> neither matches -> points_awarded = 0 (down from 40) Written explanation: Both rows changed, including the expert's, which was never touched or re-inserted between the two PATCH calls — it's the exact same row, scored twice against two different results. This is the direct, observable consequence of the route's own re-scoring behavior: because the applyResult transaction always re-reads every prediction currently on the fixture and recalculates points_awarded for all of them from scratch on every call, a correction to a wrongly-entered result automatically corrects every affected prediction's own points in the same call, rather than leaving the first (wrong) scoring decision permanently baked into rows that existed before the fix. WHY THIS WORKS AS AN ANSWER ---------------------------- It walks through a real before-and-after scoring scenario with actual numbers, shows both predictions' points_awarded values genuinely flipping (0 to 40, and 40 to 0) between the two PATCH calls, and correctly attributes the behavior to the route's own full re-scoring of every existing prediction rather than an incremental update that would only affect newly added rows.