boredgame/oldApis/games/[id]/+server.ts

21 lines
513 B
TypeScript
Raw Normal View History

2024-09-04 23:04:41 +00:00
import { getGame } from '$lib/utils/db/gameUtils.js'
import { error, json } from '@sveltejs/kit'
export const GET = async ({ locals, params }) => {
2024-09-04 23:04:41 +00:00
const game_id = Number(params.id).valueOf()
// 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' })
}
try {
2024-09-04 23:04:41 +00:00
return json(await getGame(locals, params.id))
} catch (e) {
2024-09-04 23:04:41 +00:00
console.error(e)
return new Response('Could not get gamesTable', {
status: 500,
})
}
2024-09-04 23:04:41 +00:00
}