mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-19 17:58:24 -05:00
Extract function in repotScore
This commit is contained in:
parent
eb19399984
commit
b60bde2444
|
|
@ -63,9 +63,11 @@ export function deleteResult(id: string) {
|
|||
return db.tournamentMatchGameResult.delete({ where: { id } });
|
||||
}
|
||||
|
||||
export function createParticipants(
|
||||
data: ({ matchId: string; order: TeamOrder; teamId: string } | undefined)[]
|
||||
) {
|
||||
export type CreateParticipantsData = (
|
||||
| { matchId: string; order: TeamOrder; teamId: string }
|
||||
| undefined
|
||||
)[];
|
||||
export function createParticipants(data: CreateParticipantsData) {
|
||||
return db.tournamentMatchParticipant.createMany({
|
||||
data: data.flatMap((result) => result ?? []),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -650,30 +650,9 @@ export async function reportScore({
|
|||
winner: winnerTeam.order,
|
||||
}),
|
||||
// todo: bracket reset
|
||||
TournamentMatch.createParticipants([
|
||||
match.winnerDestinationMatchId
|
||||
? {
|
||||
matchId: match.winnerDestinationMatchId,
|
||||
order: resolveNewOrder({
|
||||
bracket,
|
||||
oldMatch: match,
|
||||
newMatchId: match.winnerDestinationMatchId,
|
||||
}),
|
||||
teamId: winnerTeam.teamId,
|
||||
}
|
||||
: undefined,
|
||||
match.loserDestinationMatchId
|
||||
? {
|
||||
matchId: match.loserDestinationMatchId,
|
||||
order: resolveNewOrder({
|
||||
bracket,
|
||||
oldMatch: match,
|
||||
newMatchId: match.loserDestinationMatchId,
|
||||
}),
|
||||
teamId: loserTeam?.teamId,
|
||||
}
|
||||
: undefined,
|
||||
]),
|
||||
TournamentMatch.createParticipants(
|
||||
newParticipantsForMatches({ bracket, match, loserTeam, winnerTeam })
|
||||
),
|
||||
]);
|
||||
// otherwise if set is not over simply create result and return
|
||||
} else {
|
||||
|
|
@ -727,6 +706,43 @@ function resolveNewOrder({
|
|||
return "LOWER";
|
||||
}
|
||||
|
||||
function newParticipantsForMatches({
|
||||
bracket,
|
||||
match,
|
||||
winnerTeam,
|
||||
loserTeam,
|
||||
}: {
|
||||
bracket: NonNullable<TournamentBracket.FindById>;
|
||||
match: NonNullable<TournamentMatch.FindById>;
|
||||
winnerTeam: Unpacked<NonNullable<TournamentMatch.FindById>["participants"]>;
|
||||
loserTeam: Unpacked<NonNullable<TournamentMatch.FindById>["participants"]>;
|
||||
}): TournamentMatch.CreateParticipantsData {
|
||||
return [
|
||||
match.winnerDestinationMatchId
|
||||
? {
|
||||
matchId: match.winnerDestinationMatchId,
|
||||
order: resolveNewOrder({
|
||||
bracket,
|
||||
oldMatch: match,
|
||||
newMatchId: match.winnerDestinationMatchId,
|
||||
}),
|
||||
teamId: winnerTeam.teamId,
|
||||
}
|
||||
: undefined,
|
||||
match.loserDestinationMatchId
|
||||
? {
|
||||
matchId: match.loserDestinationMatchId,
|
||||
order: resolveNewOrder({
|
||||
bracket,
|
||||
oldMatch: match,
|
||||
newMatchId: match.loserDestinationMatchId,
|
||||
}),
|
||||
teamId: loserTeam.teamId,
|
||||
}
|
||||
: undefined,
|
||||
];
|
||||
}
|
||||
|
||||
export async function undoLastScore({
|
||||
matchId,
|
||||
position,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user