2022-08-26 05:06:39 +00:00
|
|
|
import { error } from '@sveltejs/kit';
|
2022-08-24 20:36:40 +00:00
|
|
|
import type { PageServerLoad } from './$types'
|
2022-08-29 03:48:29 +00:00
|
|
|
import { boardGameApi } from '../../api';
|
2022-09-13 22:14:55 +00:00
|
|
|
// import { Games } from '$lib/db/actions';
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2022-08-24 20:36:40 +00:00
|
|
|
type GamePageParams = {
|
|
|
|
|
params: {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 22:14:55 +00:00
|
|
|
// export const actions = {
|
|
|
|
|
// default Games.create,
|
|
|
|
|
// }
|
|
|
|
|
|
2022-08-24 20:36:40 +00:00
|
|
|
export const load: PageServerLoad = async ({ params }: GamePageParams) => {
|
|
|
|
|
console.log('params', params);
|
2022-07-11 04:17:59 +00:00
|
|
|
const queryParams = {
|
2022-07-28 00:05:54 +00:00
|
|
|
ids: `${params?.id}`
|
|
|
|
|
};
|
2022-08-29 19:18:17 +00:00
|
|
|
// console.log('queryParams', queryParams);
|
2022-07-11 04:17:59 +00:00
|
|
|
const response = await boardGameApi('get', `search`, queryParams);
|
|
|
|
|
if (response.status === 404) {
|
|
|
|
|
return {
|
2022-08-26 05:06:39 +00:00
|
|
|
game: []
|
2022-07-11 04:17:59 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2022-07-11 04:17:59 +00:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
const gameResponse = await response.json();
|
|
|
|
|
// console.log('gameResponse', gameResponse);
|
|
|
|
|
// const games = gameResponse?.games;
|
2022-08-29 19:18:17 +00:00
|
|
|
// console.log('game response', gameResponse?.games[0]);
|
2022-07-11 04:17:59 +00:00
|
|
|
return {
|
2022-08-24 20:36:40 +00:00
|
|
|
game: gameResponse?.games[0]
|
2022-07-11 04:17:59 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2022-08-26 05:06:39 +00:00
|
|
|
throw error(response.status);
|
|
|
|
|
// throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
|
2022-07-28 00:05:54 +00:00
|
|
|
};
|