match status

This commit is contained in:
yohlo
2025-09-11 14:04:05 -05:00
parent 22be6682dd
commit 8dfff139e1
8 changed files with 89 additions and 20 deletions

View File

@@ -58,6 +58,7 @@ export const generateTournamentBracket = createServerFn()
home_from_loser: match.home_from_loser || false,
away_from_loser: match.away_from_loser || false,
is_losers_bracket: false,
status: "tbd",
tournament: tournamentId,
};
@@ -77,6 +78,10 @@ export const generateTournamentBracket = createServerFn()
}
}
if (matchInput.home && matchInput.away) {
matchInput.status = "ready"
}
matchInputs.push(matchInput);
});
});
@@ -97,6 +102,7 @@ export const generateTournamentBracket = createServerFn()
home_from_loser: match.home_from_loser || false,
away_from_loser: match.away_from_loser || false,
is_losers_bracket: true,
status: "tbd",
tournament: tournamentId,
};
@@ -135,7 +141,38 @@ export const startMatch = createServerFn()
}
match = await pbAdmin.updateMatch(data, {
start_time: new Date().toISOString()
start_time: new Date().toISOString(),
status: "started"
});
return match;
}
));
const endMatchSchema = z.object({
matchId: z.string(),
home_cups: z.number(),
away_cups: z.number(),
ot_count: z.number()
});
export const endMatch = createServerFn()
.validator(endMatchSchema)
.middleware([superTokensAdminFunctionMiddleware])
.handler(async ({ data: { matchId, home_cups, away_cups, ot_count } }) =>
toServerResult(async () => {
logger.info('Ending match', matchId);
let match = await pbAdmin.getMatch(matchId);
if (!match) {
throw new Error('Match not found');
}
match = await pbAdmin.updateMatch(matchId, {
end_time: new Date().toISOString(),
status: "ended",
home_cups,
away_cups,
ot_count
})
}
));