brackt/app/models
Chris Parsons 0eb486f8d3
Fix bracket scoring logic to prefer template over DB defaults (#298)
* Emit standings-updated socket event after recalculate-floors so league pages refresh automatically

When the admin runs "Recalculate Floors" on the bracket page, the league
sports-season homepage was showing stale elimination data because there was
no mechanism to notify it of the change.

Fix: after recalculate-floors updates participant_results, emit a
standings-updated socket event to all fantasy-season draft rooms linked to
the sports season. The sports-season page now joins its draft room and
revalidates its loader whenever it receives that event for the matching
sports season.

https://claude.ai/code/session_01D3NbnVQdaH82Fk7Jm8y3sB

* Fix recalculate-floors incorrectly eliminating play-in losers who still advance

The playoff_matches.isScoring column defaults to true in the database. Brackets
created before this column was added (or before the migration set correct values)
have isScoring=true on play-in rounds that should be false. When recalculate-floors
replayed those matches, it took the "scoring round" path; since "Play-In Round 1"
isn't in ROUND_CONFIG, config===null, and the loser was assigned finalPosition=0
regardless of loserAdvances — permanently eliminating teams like the Suns who had
a second play-in game remaining.

Fix: build a round→isScoring lookup from the bracket template before replaying
matches and use it as the source of truth, falling back to the DB field only when
the template doesn't define the round. This ensures non-scoring play-in rounds
are always processed with isScoring=false so the loserAdvances guard fires
correctly.

Also revert unrelated socket changes from the previous (wrong) commit.

https://claude.ai/code/session_01D3NbnVQdaH82Fk7Jm8y3sB

* Fix isScoring fallback and loserAdvances gaps across all match-processing paths

Three issues found in code review around the recalculate-floors fix:

1. set-winner and set-round-winners (bracket.server.ts) used `match.isScoring ?? true`
   just like recalculate-floors did. Both now derive isScoring from the bracket
   template as the source of truth, falling back to the DB field only when the round
   isn't defined in the template.

2. processPlayoffEvent (scoring-calculator.ts) used `matches[0]?.isScoring ?? true`
   with the same DB-default problem. Now uses BRACKET_TEMPLATES[bracketTemplateId]
   to look up the round's isScoring before falling back to the DB field.

3. doesLoserAdvance (playoff-match.ts) was missing the AFL afl_10 Qualifying Finals
   case: both losers advance to Semi-Finals. Without this, AFL QF losers would
   incorrectly receive finalPosition=0 when processed through the non-scoring path.

https://claude.ai/code/session_01D3NbnVQdaH82Fk7Jm8y3sB

* Fix no-non-null-assertion lint errors in isScoring Map lookups

Replace Map.has(key) ? Map.get(key)! : fallback pattern with
Map.get(key) ?? fallback to satisfy oxlint no-non-null-assertion rule.

https://claude.ai/code/session_01D3NbnVQdaH82Fk7Jm8y3sB

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 11:27:00 -07:00
..
__tests__ Fix NBA Play-In Round 1 loser advancement logic (#296) 2026-04-15 09:40:53 -07:00
audit-log.ts Add audit logging for commissioner actions (#293) 2026-04-13 15:45:39 -07:00
commissioner.ts Grant sitewide admins commissioner-level access in leagues (#162) 2026-03-18 00:41:56 -07:00
cs2-major-stage.ts Add CS2 Major Qualifying Points simulator and stage management (#260) 2026-04-05 16:40:05 -04:00
draft-pick.ts Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196) 2026-03-21 10:59:51 -07:00
draft-queue.ts feat: proactively prune ineligible queue items after each pick (#59) 2026-03-02 22:07:22 -08:00
draft-slot.ts Simplify team breakdown page layout and fix code quality issues (#155) 2026-03-17 09:20:41 -07:00
draft-timer.ts Fix draft timer creation for teams without existing timers (#26) 2026-02-22 17:27:16 -08:00
draft-utils.ts feat: sort draft room and auto-pick by VORP instead of expected value 2026-04-09 02:27:40 +00:00
ev-snapshot.ts User/chris/ev f1 framework (#93) 2026-03-09 15:34:31 -07:00
event-result.ts feat: Add scoring event and results management with comprehensive scoring rules and standings tracking 2025-10-28 23:50:50 -07:00
golf-skills.ts Add golf qualifying points simulator (Plackett-Luce Monte Carlo) (#223) 2026-03-24 21:46:02 -07:00
group-stage-match.ts Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) 2026-03-29 10:27:47 -07:00
index.ts Add audit logging for commissioner actions (#293) 2026-04-13 15:45:39 -07:00
league.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
participant-expected-value.ts fix: address VORP code review issues (#283) 2026-04-08 23:20:02 -04:00
participant-result.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
participant-season-result.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
participant.ts Prevent duplicate participants within a sports season, fixes #69 (#236) 2026-03-27 01:09:04 -07:00
pending-standings-mappings.ts Add regular season standings for NBA/NHL (fixes #89) (#192) 2026-03-21 00:12:01 -07:00
playoff-match-game.ts Add playoff match game scheduling and odds management (#135) 2026-03-11 14:17:43 -07:00
playoff-match-odds.ts Add playoff match game scheduling and odds management (#135) 2026-03-11 14:17:43 -07:00
playoff-match.ts Fix bracket scoring logic to prefer template over DB defaults (#298) 2026-04-15 11:27:00 -07:00
qualifying-points.ts Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196) 2026-03-21 10:59:51 -07:00
regular-season-standings.ts Add WNBA playoff simulator with SRS-based Elo ratings, fixes #125 (#231) 2026-03-26 00:34:51 -07:00
scoring-calculator.ts Fix bracket scoring logic to prefer template over DB defaults (#298) 2026-04-15 11:27:00 -07:00
scoring-event.ts Show events on multiple dates when games span requested date range (#254) 2026-04-01 13:39:03 -07:00
scoring-rules.ts Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) 2026-03-29 10:27:47 -07:00
season-sport.ts feat: Refactor database connection handling in draft-related functions for improved flexibility 2025-10-26 20:35:55 -07:00
season-template-sport.ts refactor: remove isRequired field from season sports and templates 2025-10-13 15:00:59 -07:00
season-template.ts Improve admin dashboard stats and fix scoring event bugs (#230) 2026-03-25 20:46:54 -07:00
season.ts Replace isDraftable boolean with draftOn/draftOff date range (#263) 2026-04-05 22:09:52 -04:00
sport.ts Improve admin dashboard stats and fix scoring event bugs (#230) 2026-03-25 20:46:54 -07:00
sports-season.ts fix: league settings sports swap and audit log detail improvements (#294) 2026-04-14 21:41:05 -07:00
standings.ts Redesign standings page with sortable table, 7-day change, and chart repositioned (#205) 2026-03-22 11:05:13 -07:00
surface-elo.ts Add tennis Grand Slam simulator with surface Elo ratings, fixes #116 (#216) 2026-03-23 23:59:35 -07:00
team.ts Auto-name teams on claim and harden owner-assignment logic (#163) 2026-03-18 00:53:40 -07:00
tournament-group.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
user.ts Optimize user data fetching with batch queries and centralize display name logic (#176) 2026-03-18 16:46:07 -07:00