sendou.ink/app/modules/brackets-manager/delete.ts
Kalle eae3d529e2
Bracket component rewrite (#1653)
* Remove old code

* Add prefetching

* Elim bracket initial

* Hide rounds with only byes

* Round hiding logic

* Align stuff

* Add TODO

* Adjustments

* Deadline

* Compactify button

* Simulations

* Round robin bracket initial

* eventId -> tournamentId

* seedByTeamId removed

* Couple more TODOs

* RR placements table

* Locking matches

* Extract TournamentStream component

* Bracket streams

* Remove extras for tournament-manager, misc

* Fix E2E tests

* Fix SKALOP_SYSTEM_MESSAGE_URL in env.example

* TODOs

* TODO moved to GitHub

* Handle team changing in match cache invalidation

* Fix streamer seeing undo last score button

* Show "Sub" badge on team roster page

* Show who didn't play yet on match teams preview

* Ranked/unranked badge

* Bracket hover show roster

* Add lock/unlock match test

* Fix score reporting
2024-02-11 10:49:12 +02:00

57 lines
1.6 KiB
TypeScript

import type { Storage } from "./types";
export class Delete {
private readonly storage: Storage;
/**
* Creates an instance of Delete, which will handle cleanly deleting data in the storage.
*
* @param storage The implementation of Storage.
*/
constructor(storage: Storage) {
this.storage = storage;
}
/**
* Deletes a stage, and all its components:
*
* - Groups
* - Rounds
* - Matches
* - Match games
*
* @param stageId ID of the stage.
*/
public stage(stageId: number): void {
// The order is important here, because the abstract storage can possibly have foreign key checks (e.g. SQL).
if (!this.storage.delete("match", { stage_id: stageId }))
throw Error("Could not delete matches.");
if (!this.storage.delete("round", { stage_id: stageId }))
throw Error("Could not delete rounds.");
if (!this.storage.delete("group", { stage_id: stageId }))
throw Error("Could not delete groups.");
if (!this.storage.delete("stage", { id: stageId }))
throw Error("Could not delete the stage.");
}
/**
* Deletes **the stages** of a tournament (and all their components, see {@link stage | delete.stage()}).
*
* You are responsible for deleting the tournament itself.
*
* @param tournamentId ID of the tournament.
*/
public tournament(tournamentId: number): void {
const stages = this.storage.select("stage", {
tournament_id: tournamentId,
});
if (!stages) throw Error("Error getting the stages.");
for (const stage of stages) this.stage(stage.id);
}
}