Tournament Trophies (#3245)

This commit is contained in:
hfcRed
2026-07-31 08:51:49 +02:00
committed by GitHub
parent 293d6013be
commit 3df1f9ed19
244 changed files with 9333 additions and 242 deletions

View File

@@ -38,6 +38,7 @@ import * as TournamentMatchVodRepository from "~/features/tournament-bracket/Tou
import * as TournamentLFGRepository from "~/features/tournament-lfg/TournamentLFGRepository.server";
import * as TournamentMatchRepository from "~/features/tournament-match/TournamentMatchRepository.server";
import * as TournamentOrganizationRepository from "~/features/tournament-organization/TournamentOrganizationRepository.server";
import * as TrophyRepository from "~/features/trophies/TrophyRepository.server";
import * as UserCardRepository from "~/features/user-card/UserCardRepository.server";
import * as UserRepository from "~/features/user-page/UserRepository.server";
import * as VodRepository from "~/features/vods/VodRepository.server";
@@ -947,6 +948,21 @@ export function buildCases(fx: Fixtures): {
TournamentTeamRepository.findRecentlyPlayedMapsByIds({ teamIds }),
);
// TrophyRepository
addStatic("TrophyRepository.all", () => TrophyRepository.all());
add("TrophyRepository.findById", fx.trophy, (trophy) =>
TrophyRepository.findById(trophy.heavyTrophyId),
);
add("TrophyRepository.findByOwnerUserId", fx.trophy, (trophy) =>
TrophyRepository.findByOwnerUserId(trophy.ownerUserId),
);
add("TrophyRepository.findTournamentsByTrophyId", fx.trophy, (trophy) =>
TrophyRepository.findTournamentsByTrophyId(trophy.heavyTrophyId),
);
add("TrophyRepository.findWinsByOwner", fx.trophy, (trophy) =>
TrophyRepository.findWinsByOwner(trophy.wins),
);
// UserCardRepository
add("UserCardRepository.findAllByUserIds", fx.manyUserIds, (userIds) =>
UserCardRepository.findAllByUserIds({

View File

@@ -61,6 +61,11 @@ export interface Fixtures {
badgeOwnerUserId: number | null;
badgeAuthorId: number | null;
badgeManagerUserId: number | null;
trophy: {
heavyTrophyId: number;
ownerUserId: number;
wins: { trophyId: number; userId: number };
} | null;
manyUserIds: number[] | null;
notification: { userId: number; type: Tables["Notification"]["type"] } | null;
heavyAssociation: {
@@ -143,6 +148,7 @@ export async function resolveFixtures(): Promise<Fixtures> {
badgeOwnerUserId: await resolveBadgeOwnerUserId(),
badgeAuthorId: await resolveBadgeAuthorId(),
badgeManagerUserId: await resolveBadgeManagerUserId(),
trophy: await resolveTrophy(),
manyUserIds: await resolveManyUserIds(heavyTournamentId),
notification: await resolveNotification(),
heavyAssociation: await resolveHeavyAssociation(),
@@ -782,6 +788,45 @@ async function resolveBadgeManagerUserId() {
return row?.userId ?? null;
}
async function resolveTrophy() {
const heavyTrophyRow = await db
.selectFrom("TrophyOwner")
.select(({ fn }) => ["trophyId", fn.countAll<number>().as("count")])
.groupBy("trophyId")
.orderBy("count", "desc")
.limit(1)
.executeTakeFirst();
if (!heavyTrophyRow) return null;
const ownerRow = await db
.selectFrom("TrophyOwner")
.select(({ fn }) => ["userId", fn.countAll<number>().as("count")])
.groupBy("userId")
.orderBy("count", "desc")
.limit(1)
.executeTakeFirst();
if (!ownerRow) return null;
const winsRow = await db
.selectFrom("TrophyOwner")
.select(({ fn }) => [
"trophyId",
"userId",
fn.countAll<number>().as("count"),
])
.groupBy(["trophyId", "userId"])
.orderBy("count", "desc")
.limit(1)
.executeTakeFirst();
if (!winsRow) return null;
return {
heavyTrophyId: heavyTrophyRow.trophyId,
ownerUserId: ownerRow.userId,
wins: { trophyId: winsRow.trophyId, userId: winsRow.userId },
};
}
async function resolveManyUserIds(heavyTournamentId: number | null) {
if (heavyTournamentId !== null) {
const rows = await db