2024-09-04 23:04:41 +00:00
|
|
|
import { getGame } from '$lib/utils/db/gameUtils.js'
|
|
|
|
|
import { error, json } from '@sveltejs/kit'
|
2024-02-21 07:31:05 +00:00
|
|
|
|
|
|
|
|
export const GET = async ({ locals, params }) => {
|
2024-09-04 23:04:41 +00:00
|
|
|
const game_id = Number(params.id).valueOf()
|
2024-02-21 07:31:05 +00:00
|
|
|
|
|
|
|
|
// TODO: Debounce excessive calls and possibly throttle
|
|
|
|
|
if (isNaN(game_id) || !isFinite(game_id)) {
|
2024-09-04 23:04:41 +00:00
|
|
|
error(400, { message: 'Invalid game id' })
|
2024-02-21 07:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2024-09-04 23:04:41 +00:00
|
|
|
return json(await getGame(locals, params.id))
|
2024-02-21 07:31:05 +00:00
|
|
|
} catch (e) {
|
2024-09-04 23:04:41 +00:00
|
|
|
console.error(e)
|
|
|
|
|
return new Response('Could not get gamesTable', {
|
|
|
|
|
status: 500,
|
|
|
|
|
})
|
2024-02-21 07:31:05 +00:00
|
|
|
}
|
2024-09-04 23:04:41 +00:00
|
|
|
}
|