From 7aef29c47af99423251eaa31839780d00653559b Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 9 Apr 2022 12:41:47 +0300 Subject: [PATCH] Order in bracket with position, display number --- app/core/tournament/bracket.ts | 2 ++ app/models/TournamentBracket.server.ts | 4 ++++ app/services/bracket.ts | 3 ++- app/services/tournament.ts | 3 ++- .../20220409090909_tournament_match_add_number/migration.sql | 5 +++++ prisma/schema.prisma | 1 + 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20220409090909_tournament_match_add_number/migration.sql diff --git a/app/core/tournament/bracket.ts b/app/core/tournament/bracket.ts index 7096d05e1..29ebcb30c 100644 --- a/app/core/tournament/bracket.ts +++ b/app/core/tournament/bracket.ts @@ -243,6 +243,7 @@ export interface TournamentRoundForDB { matches: { id: string; number: number; + position: number; winnerDestinationMatchId?: string; loserDestinationMatchId?: string; participants: { @@ -282,6 +283,7 @@ export function tournamentRoundsForDB({ const matches = round.map((match) => { return { id: match.id, + position: match.position, number: match.number, winnerDestinationMatchId: match.winnerDestinationMatch?.id, loserDestinationMatchId: match.loserDestinationMatch?.id, diff --git a/app/models/TournamentBracket.server.ts b/app/models/TournamentBracket.server.ts index 9350fb523..f6c19c174 100644 --- a/app/models/TournamentBracket.server.ts +++ b/app/models/TournamentBracket.server.ts @@ -19,6 +19,7 @@ export function findById(bracketId: string) { matches: { select: { id: true, + number: true, position: true, winnerDestinationMatchId: true, loserDestinationMatchId: true, @@ -39,6 +40,9 @@ export function findById(bracketId: string) { }, }, }, + orderBy: { + position: "asc", + }, }, }, }, diff --git a/app/services/bracket.ts b/app/services/bracket.ts index ac6c51f03..e6af89aae 100644 --- a/app/services/bracket.ts +++ b/app/services/bracket.ts @@ -108,7 +108,8 @@ function modifyRounds( ] : undefined; return { - number: match.position, + // TODO: match.number could be made mandatory in DB and this would become redundant + number: match.number ?? match.position, id: match.id, winnerDestinationMatchId: match.winnerDestinationMatchId, loserDestinationMatchId: match.loserDestinationMatchId, diff --git a/app/services/tournament.ts b/app/services/tournament.ts index 0cb88fc0e..7dd50db40 100644 --- a/app/services/tournament.ts +++ b/app/services/tournament.ts @@ -126,7 +126,8 @@ export async function createTournamentRounds({ data: rounds.flatMap((round) => { return round.matches.map((match) => ({ id: match.id, - position: match.number, + number: match.number, + position: match.position, roundId: round.id, winnerDestinationMatchId: match.winnerDestinationMatchId, loserDestinationMatchId: match.loserDestinationMatchId, diff --git a/prisma/migrations/20220409090909_tournament_match_add_number/migration.sql b/prisma/migrations/20220409090909_tournament_match_add_number/migration.sql new file mode 100644 index 000000000..1a36d8edf --- /dev/null +++ b/prisma/migrations/20220409090909_tournament_match_add_number/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "TournamentMatch" ADD COLUMN "number" INTEGER; + +-- AddForeignKey +ALTER TABLE "GameDetail" ADD CONSTRAINT "GameDetail_lfgStageId_fkey" FOREIGN KEY ("lfgStageId") REFERENCES "LfgGroupMatchStage"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 36036dab7..d1ad9f881 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -168,6 +168,7 @@ model TournamentRoundStage { model TournamentMatch { id String @id @default(uuid()) roundId String + number Int? position Int // for SE/DE destination based on the result - if no winner destination then winner has won the tournament, if no loser destination loser is eliminated winnerDestinationMatchId String?