sendou.ink/app/modules/brackets-manager/reset.ts
Kalle ef78d3a2c2
Tournament full (#1373)
* Got something going

* Style overwrites

* width != height

* More playing with lines

* Migrations

* Start bracket initial

* Unhardcode stage generation params

* Link to match page

* Matches page initial

* Support directly adding seed to map list generator

* Add docs

* Maps in matches page

* Add invariant about tie breaker map pool

* Fix PICNIC lacking tie breaker maps

* Only link in bracket when tournament has started

* Styled tournament roster inputs

* Prefer IGN in tournament match page

* ModeProgressIndicator

* Some conditional rendering

* Match action initial + better error display

* Persist bestOf in DB

* Resolve best of ahead of time

* Move brackets-manager to core

* Score reporting works

* Clear winner on score report

* ModeProgressIndicator: highlight winners

* Fix inconsistent input

* Better text when submitting match

* mapCountPlayedInSetWithCertainty that works

* UNDO_REPORT_SCORE implemented

* Permission check when starting tournament

* Remove IGN from upsert

* View match results page

* Source in DB

* Match page waiting for teams

* Move tournament bracket to feature folder

* REOPEN_MATCH initial

* Handle proper resetting of match

* Inline bracket-manager

* Syncify

* Transactions

* Handle match is locked gracefully

* Match page auto refresh

* Fix match refresh called "globally"

* Bracket autoupdate

* Move fillWithNullTillPowerOfTwo to utils with testing

* Fix map lists not visible after tournament started

* Optimize match events

* Show UI while in progress to members

* Fix start tournament alert not being responsive

* Teams can check in

* Fix map list 400

* xxx -> TODO

* Seeds page

* Remove map icons for team page

* Don't display link to seeds after tournament has started

* Admin actions initial

* Change captain admin action

* Make all hooks ts

* Admin actions functioning

* Fix validate error not displaying in CatchBoundary

* Adjust validate args order

* Remove admin loader

* Make delete team button menancing

* Only include checked in teams to bracket

* Optimize to.id route loads

* Working show map list generator toggle

* Update full tournaments flow

* Make full tournaments work with many start times

* Handle undefined in crud

* Dynamic stage banner

* Handle default strat if map list generation fails

* Fix crash on brackets if less than 2 teams

* Add commented out test for reference

* Add TODO

* Add players from team during register

* TrustRelationship

* Prefers not to host feature

* Last before merge

* Rename some vars

* More renames
2023-05-15 22:37:43 +03:00

99 lines
3.3 KiB
TypeScript

import { Status } from "brackets-model";
import { BaseUpdater } from "./base/updater";
import * as helpers from "./helpers";
export class Reset extends BaseUpdater {
/**
* Resets the results of a match.
*
* This will update related matches accordingly.
*
* @param matchId ID of the match.
*/
public matchResults(matchId: number): void {
const stored = this.storage.select("match", matchId);
if (!stored) throw Error("Match not found.");
// The user can handle forfeits with matches which have child games in two possible ways:
//
// 1. Set forfeits for the parent match directly.
// --> The child games will never be updated: not locked, not finished, without forfeit. They will just be ignored and never be played.
// --> To reset the forfeits, the user has to reset the parent match, with `reset.matchResults()`.
// --> `reset.matchResults()` will be usable **only** to reset the forfeit of the parent match. Otherwise it will throw the error below.
//
// 2. Set forfeits for each child game.
// --> The parent match won't automatically have a forfeit, but will be updated with a computed score according to the forfeited match games.
// --> To reset the forfeits, the user has to reset each child game on its own, with `reset.matchGameResults()`.
// --> `reset.matchResults()` will throw the error below in all cases.
if (!helpers.isMatchForfeitCompleted(stored) && stored.child_count > 0)
throw Error(
"The parent match is controlled by its child games and its result cannot be reset."
);
const stage = this.storage.select("stage", stored.stage_id);
if (!stage) throw Error("Stage not found.");
const group = this.storage.select("group", stored.group_id);
if (!group) throw Error("Group not found.");
const { roundNumber, roundCount } = this.getRoundPositionalInfo(
stored.round_id
);
const matchLocation = helpers.getMatchLocation(stage.type, group.number);
const nextMatches = this.getNextMatches(
stored,
matchLocation,
stage,
roundNumber,
roundCount
);
if (
nextMatches.some(
(match) =>
match &&
match.status >= Status.Running &&
!helpers.isMatchByeCompleted(match)
)
)
throw Error("The match is locked.");
helpers.resetMatchResults(stored);
this.applyMatchUpdate(stored);
if (!helpers.isRoundRobin(stage))
this.updateRelatedMatches(stored, true, true);
}
/**
* Resets the results of a match game.
*
* @param gameId ID of the match game.
*/
public matchGameResults(gameId: number): void {
const stored = this.storage.select("match_game", gameId);
if (!stored) throw Error("Match game not found.");
const stage = this.storage.select("stage", stored.stage_id);
if (!stage) throw Error("Stage not found.");
const inRoundRobin = helpers.isRoundRobin(stage);
helpers.resetMatchResults(stored);
if (!this.storage.update("match_game", stored.id, stored))
throw Error("Could not update the match game.");
this.updateParentMatch(stored.parent_id, inRoundRobin);
}
/**
* Resets the seeding of a stage.
*
* @param stageId ID of the stage.
*/
public seeding(stageId: number): void {
this.updateSeeding(stageId, null);
}
}