tcl-guessr/src/routes/results/+page.server.ts

27 lines
767 B
TypeScript

import type { PageServerLoad } from "./$types";
import { error } from "@sveltejs/kit";
interface JoinedRoundScore {
mode: string;
total_score: number;
points: number;
distance: number;
stop_name: string;
}
export const load: PageServerLoad = async ({ url, platform }) => {
const db = platform?.env?.TCL_GUESSR_D1;
if (!db) error(500, "could not connect to d1");
const gameId = url.searchParams.get("gameId");
if (!gameId) error(400, "gameId was not specified");
const { results } = await db
.prepare(
"SELECT game.mode, game.total_score, round.points, round.distance, round.stop_name FROM game INNER JOIN round ON round.game_id = game.id WHERE game.id = ?;",
)
.bind(gameId)
.all<JoinedRoundScore>();
return { rounds: results, gameId };
};