mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
parent
c78525c92c
commit
31244b2d7c
|
|
@ -108,7 +108,9 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||
finalizeTournament(tournamentId);
|
||||
}
|
||||
|
||||
await updateSeriesTierHistory(tournament);
|
||||
if (!tournament.isTest) {
|
||||
await updateSeriesTierHistory(tournament);
|
||||
}
|
||||
|
||||
if (tournament.ranked) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/sqlite";
|
|||
import { db } from "~/db/sql";
|
||||
import type { Tables, TablesInsertable } from "~/db/tables";
|
||||
import {
|
||||
TIER_HISTORY_LENGTH,
|
||||
type TournamentTierNumber,
|
||||
updateTierHistory,
|
||||
} from "~/features/tournament/core/tiering";
|
||||
|
|
@ -422,7 +423,7 @@ export function update({
|
|||
.execute();
|
||||
|
||||
if (series.length > 0) {
|
||||
await trx
|
||||
const insertedSeries = await trx
|
||||
.insertInto("TournamentOrganizationSeries")
|
||||
.values(
|
||||
series.map((s) => ({
|
||||
|
|
@ -433,7 +434,54 @@ export function update({
|
|||
showLeaderboard: Number(s.showLeaderboard),
|
||||
})),
|
||||
)
|
||||
.returning(["id", "substringMatches"])
|
||||
.execute();
|
||||
|
||||
const finalizedTournaments = await trx
|
||||
.selectFrom("Tournament")
|
||||
.innerJoin(
|
||||
"CalendarEvent",
|
||||
"CalendarEvent.tournamentId",
|
||||
"Tournament.id",
|
||||
)
|
||||
.innerJoin(
|
||||
"CalendarEventDate",
|
||||
"CalendarEventDate.eventId",
|
||||
"CalendarEvent.id",
|
||||
)
|
||||
.select([
|
||||
"Tournament.id as tournamentId",
|
||||
"CalendarEvent.name",
|
||||
"Tournament.tier",
|
||||
"CalendarEventDate.startTime",
|
||||
])
|
||||
.where("Tournament.isFinalized", "=", 1)
|
||||
.where("CalendarEvent.organizationId", "=", id)
|
||||
.where("CalendarEvent.hidden", "=", 0)
|
||||
.orderBy("CalendarEventDate.startTime", "asc")
|
||||
.execute();
|
||||
|
||||
for (const s of insertedSeries) {
|
||||
const matchingTiers = finalizedTournaments
|
||||
.filter((t) => {
|
||||
const eventNameLower = t.name.toLowerCase();
|
||||
return s.substringMatches.some((match) =>
|
||||
eventNameLower.includes(match.toLowerCase()),
|
||||
);
|
||||
})
|
||||
.filter((t) => t.tier !== null)
|
||||
.map((t) => t.tier);
|
||||
|
||||
if (matchingTiers.length === 0) continue;
|
||||
|
||||
const tierHistory = matchingTiers.slice(-TIER_HISTORY_LENGTH);
|
||||
|
||||
await trx
|
||||
.updateTable("TournamentOrganizationSeries")
|
||||
.set({ tierHistory: JSON.stringify(tierHistory) })
|
||||
.where("id", "=", s.id)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
await trx
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ function getTournamentsWithOrg(): TournamentWithOrg[] {
|
|||
INNER JOIN CalendarEvent ce ON ce.tournamentId = t.id
|
||||
INNER JOIN CalendarEventDate ced ON ced.eventId = ce.id
|
||||
WHERE t.isFinalized = 1
|
||||
AND ce.hidden = 0
|
||||
ORDER BY ced.startTime ASC
|
||||
`;
|
||||
return sql.prepare(query).all() as TournamentWithOrg[];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user