mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 01:09:02 -05:00
* 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
348 lines
8.3 KiB
TypeScript
348 lines
8.3 KiB
TypeScript
/* eslint-disable */
|
|
// @ts-nocheck TODO
|
|
|
|
import { Stage, Team, Group, Round, Match } from "./crud-db.server";
|
|
|
|
export class SqlDatabase {
|
|
insert(table, arg) {
|
|
switch (table) {
|
|
case "participant":
|
|
throw new Error("not implemented");
|
|
return Team.insertMissing(arg);
|
|
|
|
case "stage":
|
|
const stage = new Stage(
|
|
undefined,
|
|
arg.tournament_id,
|
|
arg.number,
|
|
arg.name,
|
|
arg.type,
|
|
JSON.stringify(arg.settings)
|
|
);
|
|
return stage.insert() && stage.id;
|
|
|
|
case "group":
|
|
const group = new Group(undefined, arg.stage_id, arg.number);
|
|
return group.insert() && group.id;
|
|
|
|
case "round":
|
|
const round = new Round(
|
|
undefined,
|
|
arg.stage_id,
|
|
arg.group_id,
|
|
arg.number
|
|
);
|
|
return round.insert() && round.id;
|
|
|
|
case "match":
|
|
const match = new Match(
|
|
undefined,
|
|
arg.status,
|
|
arg.stage_id,
|
|
arg.group_id,
|
|
arg.round_id,
|
|
arg.number,
|
|
arg.child_count,
|
|
null,
|
|
null,
|
|
null,
|
|
JSON.stringify(arg.opponent1),
|
|
JSON.stringify(arg.opponent2)
|
|
);
|
|
return match.insert() && match.id;
|
|
|
|
case "match_game":
|
|
throw new Error("not implemented");
|
|
const matchGame = new MatchGame(
|
|
undefined,
|
|
arg.stage_id,
|
|
arg.parent_id,
|
|
arg.status,
|
|
arg.number,
|
|
null,
|
|
null,
|
|
null,
|
|
JSON.stringify(arg.opponent1),
|
|
JSON.stringify(arg.opponent2)
|
|
);
|
|
return matchGame.insert() && matchGame.id;
|
|
}
|
|
}
|
|
|
|
select(table, arg) {
|
|
switch (table) {
|
|
case "participant":
|
|
if (typeof arg === "number") {
|
|
throw new Error("not implemented");
|
|
const team = Team.getById(arg);
|
|
return team && convertTeam(team);
|
|
}
|
|
|
|
if (arg.tournament_id) {
|
|
return Team.getByTournamentId(arg.tournament_id);
|
|
}
|
|
|
|
break;
|
|
|
|
case "stage":
|
|
if (typeof arg === "number") {
|
|
return Stage.getById(arg);
|
|
}
|
|
|
|
if (arg.tournament_id && arg.number) {
|
|
throw new Error("not implemented");
|
|
const stage = Stage.getByTournamentAndNumber(
|
|
arg.tournament_id,
|
|
arg.number
|
|
);
|
|
return stage && [convertStage(stage)];
|
|
}
|
|
|
|
if (arg.tournament_id) {
|
|
return Stage.getByTournamentId(arg.tournament_id);
|
|
}
|
|
|
|
break;
|
|
|
|
case "group":
|
|
if (!arg) {
|
|
throw new Error("not implemented");
|
|
const groups = Group.getAll();
|
|
return groups && groups.map(convertGroup);
|
|
}
|
|
|
|
if (typeof arg === "number") {
|
|
return Group.getById(arg);
|
|
}
|
|
|
|
if (arg.stage_id && arg.number) {
|
|
const group = Group.getByStageAndNumber(arg.stage_id, arg.number);
|
|
return group && [group];
|
|
}
|
|
|
|
if (arg.stage_id) {
|
|
return Group.getByStageId(arg.stage_id);
|
|
}
|
|
|
|
break;
|
|
|
|
case "round":
|
|
if (!arg) {
|
|
throw new Error("not implemented");
|
|
const rounds = Round.getAll();
|
|
return rounds && rounds.map(convertRound);
|
|
}
|
|
|
|
if (typeof arg === "number") {
|
|
return Round.getById(arg);
|
|
}
|
|
|
|
if (arg.group_id && arg.number) {
|
|
const round = Round.getByGroupAndNumber(arg.group_id, arg.number);
|
|
return round && [round];
|
|
}
|
|
|
|
if (arg.group_id) {
|
|
return Round.getByGroupId(arg.group_id);
|
|
}
|
|
|
|
if (arg.stage_id) {
|
|
return Round.getByStageId(arg.stage_id);
|
|
}
|
|
|
|
break;
|
|
|
|
case "match":
|
|
if (!arg) {
|
|
throw new Error("not implemented");
|
|
const matches = Match.getAll();
|
|
return matches && matches.map(convertMatch);
|
|
}
|
|
|
|
if (typeof arg === "number") {
|
|
return Match.getById(arg);
|
|
}
|
|
|
|
if (arg.round_id && arg.number) {
|
|
const match = Match.getByRoundAndNumber(arg.round_id, arg.number);
|
|
return match && [match];
|
|
}
|
|
|
|
if (arg.stage_id) {
|
|
return Match.getByStageId(arg.stage_id);
|
|
}
|
|
|
|
if (arg.group_id) {
|
|
throw new Error("not implemented");
|
|
const matches = Match.getByGroupId(arg.group_id);
|
|
return matches && matches.map(convertMatch);
|
|
}
|
|
|
|
if (arg.round_id) {
|
|
throw new Error("not implemented");
|
|
const matches = Match.getByRoundId(arg.round_id);
|
|
return matches && matches.map(convertMatch);
|
|
}
|
|
|
|
break;
|
|
|
|
case "match_game":
|
|
throw new Error("not implemented");
|
|
if (typeof arg === "number") {
|
|
const game = MatchGame.getById(arg);
|
|
return game && convertMatchGame(game);
|
|
}
|
|
|
|
if (arg.parent_id && arg.number) {
|
|
const game = MatchGame.getByParentAndNumber(
|
|
arg.parent_id,
|
|
arg.number
|
|
);
|
|
return game && [convertMatchGame(game)];
|
|
}
|
|
|
|
if (arg.parent_id) {
|
|
const games = MatchGame.getByParentId(arg.parent_id);
|
|
return games && games.map(convertMatchGame);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
update(table, query, update) {
|
|
switch (table) {
|
|
case "stage":
|
|
if (typeof query === "number") {
|
|
return Stage.updateSettings(query, JSON.stringify(update.settings));
|
|
}
|
|
|
|
break;
|
|
|
|
case "match":
|
|
if (typeof query === "number") {
|
|
const match = new Match(
|
|
query,
|
|
update.status,
|
|
update.stage_id,
|
|
update.group_id,
|
|
update.round_id,
|
|
update.number,
|
|
update.child_count,
|
|
null,
|
|
null,
|
|
null,
|
|
JSON.stringify(update.opponent1),
|
|
JSON.stringify(update.opponent2)
|
|
);
|
|
|
|
return match.update();
|
|
}
|
|
|
|
if (query.stage_id)
|
|
return Match.updateChildCountByStage(
|
|
query.stage_id,
|
|
update.child_count
|
|
);
|
|
|
|
if (query.group_id)
|
|
return Match.updateChildCountByGroup(
|
|
query.group_id,
|
|
update.child_count
|
|
);
|
|
|
|
if (query.round_id)
|
|
return Match.updateChildCountByRound(
|
|
query.round_id,
|
|
update.child_count
|
|
);
|
|
|
|
break;
|
|
|
|
case "match_game":
|
|
throw new Error("not implemented");
|
|
if (typeof query === "number") {
|
|
const game = new MatchGame(
|
|
query,
|
|
update.stage_id,
|
|
update.parent_id,
|
|
update.status,
|
|
update.number,
|
|
null,
|
|
null,
|
|
null,
|
|
JSON.stringify(update.opponent1),
|
|
JSON.stringify(update.opponent2)
|
|
);
|
|
|
|
return game.update();
|
|
}
|
|
|
|
if (query.parent_id) {
|
|
const game = new MatchGame(
|
|
undefined,
|
|
update.stage_id,
|
|
query.parent_id,
|
|
update.status,
|
|
update.number,
|
|
null,
|
|
null,
|
|
null,
|
|
JSON.stringify(update.opponent1),
|
|
JSON.stringify(update.opponent2)
|
|
);
|
|
|
|
return game.updateByParentId();
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
delete(table, filter) {
|
|
throw new Error("not implemented");
|
|
switch (table) {
|
|
case "stage":
|
|
return Number.isInteger(filter.id) && Stage.deleteById(filter.id);
|
|
|
|
case "group":
|
|
return (
|
|
Number.isInteger(filter.stage_id) &&
|
|
Group.deleteByStageId(filter.stage_id)
|
|
);
|
|
|
|
case "round":
|
|
return (
|
|
Number.isInteger(filter.stage_id) &&
|
|
Round.deleteByStageId(filter.stage_id)
|
|
);
|
|
|
|
case "match":
|
|
return (
|
|
Number.isInteger(filter.stage_id) &&
|
|
Match.deleteByStageId(filter.stage_id)
|
|
);
|
|
|
|
case "match_game":
|
|
if (Number.isInteger(filter.stage_id))
|
|
return MatchGame.deleteByStageId(filter.stage_id);
|
|
if (
|
|
Number.isInteger(filter.parent_id) &&
|
|
Number.isInteger(filter.number)
|
|
)
|
|
return MatchGame.deleteByParentAndNumber(
|
|
filter.parent_id,
|
|
filter.number
|
|
);
|
|
else return false;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|