mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 06:08:13 -05:00
Move related functions to TournamentTeamRepository
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
import { createSwissBracketInTransaction } from "~/features/tournament/queries/createSwissBracketInTransaction.server";
|
||||
import { updateRoundMaps } from "~/features/tournament/queries/updateRoundMaps.server";
|
||||
import * as TournamentRepository from "~/features/tournament/TournamentRepository.server";
|
||||
import * as TournamentTeamRepository from "~/features/tournament/TournamentTeamRepository.server";
|
||||
import * as Progression from "~/features/tournament-bracket/core/Progression";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { logger } from "~/utils/logger";
|
||||
@@ -287,7 +288,7 @@ export const action: ActionFunction = async ({ params, request }) => {
|
||||
`Checking in (bracket try): tournament team id: ${teamMemberOf.id} - user id: ${user.id} - tournament id: ${tournament.ctx.id} - bracket idx: ${data.bracketIdx}`,
|
||||
);
|
||||
|
||||
await TournamentRepository.checkIn({
|
||||
await TournamentTeamRepository.checkIn({
|
||||
bracketIdx: data.bracketIdx,
|
||||
tournamentTeamId: teamMemberOf.id,
|
||||
});
|
||||
|
||||
@@ -646,68 +646,6 @@ export async function friendCodesByTournamentId(tournamentId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
export function checkIn({
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
bracketIdx: number | null;
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
let query = trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId)
|
||||
.where("TournamentTeamCheckIn.isCheckOut", "=", 1);
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
query = query.where("TournamentTeamCheckIn.bracketIdx", "=", bracketIdx);
|
||||
}
|
||||
|
||||
await query.execute();
|
||||
|
||||
await trx
|
||||
.insertInto("TournamentTeamCheckIn")
|
||||
.values({
|
||||
checkedInAt: dateToDatabaseTimestamp(new Date()),
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
})
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
export function checkOut({
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
bracketIdx: number | null;
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
let query = trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId);
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
query = query.where("TournamentTeamCheckIn.bracketIdx", "=", bracketIdx);
|
||||
}
|
||||
|
||||
await query.execute();
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
await trx
|
||||
.insertInto("TournamentTeamCheckIn")
|
||||
.values({
|
||||
checkedInAt: dateToDatabaseTimestamp(new Date()),
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
isCheckOut: 1,
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function updateProgression({
|
||||
tournamentId,
|
||||
bracketProgression,
|
||||
@@ -800,56 +738,6 @@ export function overrideTeamBracketProgression({
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function updateTeamName({
|
||||
tournamentTeamId,
|
||||
name,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
name: string;
|
||||
}) {
|
||||
return db
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
name,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function dropTeamOut({
|
||||
tournamentTeamId,
|
||||
previewBracketIdxs,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
previewBracketIdxs: number[];
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
await trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("tournamentTeamId", "=", tournamentTeamId)
|
||||
.where("TournamentTeamCheckIn.bracketIdx", "in", previewBracketIdxs)
|
||||
.execute();
|
||||
|
||||
await trx
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
droppedOut: 1,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
export function undoDropTeamOut(tournamentTeamId: number) {
|
||||
return db
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
droppedOut: 0,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function addStaff({
|
||||
tournamentId,
|
||||
userId,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// TODO: add rest of the functions here that relate more to tournament teams than tournament/bracket
|
||||
|
||||
import type { Transaction } from "kysely";
|
||||
import { sql } from "kysely";
|
||||
import { db } from "~/db/sql";
|
||||
import type { DB, Tables } from "~/db/tables";
|
||||
import type { ModeShort, StageId } from "~/modules/in-game-lists/types";
|
||||
import { flatZip } from "~/utils/arrays";
|
||||
import { databaseTimestampNow } from "~/utils/dates";
|
||||
import { databaseTimestampNow, dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { shortNanoid } from "~/utils/id";
|
||||
import invariant from "~/utils/invariant";
|
||||
|
||||
@@ -357,6 +355,118 @@ export function updateStartingBrackets(
|
||||
});
|
||||
}
|
||||
|
||||
export function checkIn({
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
bracketIdx: number | null;
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
let query = trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId)
|
||||
.where("TournamentTeamCheckIn.isCheckOut", "=", 1);
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
query = query.where("TournamentTeamCheckIn.bracketIdx", "=", bracketIdx);
|
||||
}
|
||||
|
||||
await query.execute();
|
||||
|
||||
await trx
|
||||
.insertInto("TournamentTeamCheckIn")
|
||||
.values({
|
||||
checkedInAt: dateToDatabaseTimestamp(new Date()),
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
})
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
export function checkOut({
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
bracketIdx: number | null;
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
let query = trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId);
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
query = query.where("TournamentTeamCheckIn.bracketIdx", "=", bracketIdx);
|
||||
}
|
||||
|
||||
await query.execute();
|
||||
|
||||
if (typeof bracketIdx === "number") {
|
||||
await trx
|
||||
.insertInto("TournamentTeamCheckIn")
|
||||
.values({
|
||||
checkedInAt: dateToDatabaseTimestamp(new Date()),
|
||||
tournamentTeamId,
|
||||
bracketIdx,
|
||||
isCheckOut: 1,
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function updateName({
|
||||
tournamentTeamId,
|
||||
name,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
name: string;
|
||||
}) {
|
||||
return db
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
name,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function dropOut({
|
||||
tournamentTeamId,
|
||||
previewBracketIdxs,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
previewBracketIdxs: number[];
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
await trx
|
||||
.deleteFrom("TournamentTeamCheckIn")
|
||||
.where("tournamentTeamId", "=", tournamentTeamId)
|
||||
.where("TournamentTeamCheckIn.bracketIdx", "in", previewBracketIdxs)
|
||||
.execute();
|
||||
|
||||
await trx
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
droppedOut: 1,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
export function undoDropOut(tournamentTeamId: number) {
|
||||
return db
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
droppedOut: 0,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
async function findTeamRecentMaps(teamId: number, limit: number) {
|
||||
return db
|
||||
.selectFrom("TournamentMatchGameResult")
|
||||
|
||||
@@ -121,7 +121,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
const team = tournament.teamById(data.teamId);
|
||||
errorToastIfFalsy(team, "Invalid team id");
|
||||
|
||||
await TournamentRepository.updateTeamName({
|
||||
await TournamentTeamRepository.updateName({
|
||||
tournamentTeamId: data.teamId,
|
||||
name: data.teamName,
|
||||
});
|
||||
@@ -147,7 +147,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
invariant(bracket, "Invalid bracket idx");
|
||||
errorToastIfFalsy(bracket.preview, "Bracket has been started");
|
||||
|
||||
await TournamentRepository.checkIn({
|
||||
await TournamentTeamRepository.checkIn({
|
||||
tournamentTeamId: data.teamId,
|
||||
// no sources = regular check in
|
||||
bracketIdx: !bracket.sources ? null : data.bracketIdx,
|
||||
@@ -169,7 +169,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
invariant(bracket, "Invalid bracket idx");
|
||||
errorToastIfFalsy(bracket.preview, "Bracket has been started");
|
||||
|
||||
await TournamentRepository.checkOut({
|
||||
await TournamentTeamRepository.checkOut({
|
||||
tournamentTeamId: data.teamId,
|
||||
// no sources = regular check in
|
||||
bracketIdx: !bracket.sources ? null : data.bracketIdx,
|
||||
@@ -402,7 +402,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
droppedTeamId: data.teamId,
|
||||
});
|
||||
|
||||
await TournamentRepository.dropTeamOut({
|
||||
await TournamentTeamRepository.dropOut({
|
||||
tournamentTeamId: data.teamId,
|
||||
previewBracketIdxs: tournament.brackets.flatMap((b, idx) =>
|
||||
b.preview ? idx : [],
|
||||
@@ -415,7 +415,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
case "UNDO_DROP_TEAM_OUT": {
|
||||
validateIsTournamentOrganizer();
|
||||
|
||||
await TournamentRepository.undoDropTeamOut(data.teamId);
|
||||
await TournamentTeamRepository.undoDropOut(data.teamId);
|
||||
|
||||
message = "Team drop out undone";
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,6 @@ import { getServerTournamentManager } from "../tournament-bracket/core/brackets-
|
||||
import { tournamentFromDB } from "../tournament-bracket/core/Tournament.server";
|
||||
import { joinTeam } from "./queries/joinLeaveTeam.server";
|
||||
import { updateRoundMaps } from "./queries/updateRoundMaps.server";
|
||||
import * as TournamentRepository from "./TournamentRepository.server";
|
||||
import * as TournamentTeamRepository from "./TournamentTeamRepository.server";
|
||||
|
||||
/**
|
||||
@@ -79,7 +78,7 @@ export async function dbInsertTournamentTeam({
|
||||
});
|
||||
}
|
||||
|
||||
await TournamentRepository.checkIn({
|
||||
await TournamentTeamRepository.checkIn({
|
||||
tournamentTeamId: tournamentTeam.id,
|
||||
// no sources = regular check in
|
||||
bracketIdx: null,
|
||||
|
||||
Reference in New Issue
Block a user