2022-08-26 05:06:39 +00:00
|
|
|
import { error } from '@sveltejs/kit';
|
2022-12-25 18:52:36 +00:00
|
|
|
import type { PageServerLoad } from './$types';
|
2022-08-29 03:48:29 +00:00
|
|
|
import { boardGameApi } from '../../api';
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2022-12-27 07:15:41 +00:00
|
|
|
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
2022-12-25 18:52:36 +00:00
|
|
|
const queryParams = {
|
2023-01-08 08:35:40 +00:00
|
|
|
ids: `${params?.id}`,
|
|
|
|
|
fields:
|
2023-01-08 19:46:22 +00:00
|
|
|
'id,name,price,min_age,min_players,max_players,thumb_url,playtime,min_playtime,max_playtime,min_age,description,year_published,image_url'
|
2022-12-25 18:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await boardGameApi('get', `search`, queryParams);
|
|
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const gameResponse = await response.json();
|
2022-08-24 20:36:40 +00:00
|
|
|
|
2022-12-25 18:52:36 +00:00
|
|
|
setHeaders({
|
|
|
|
|
'Cache-Control': 'max-age=3600'
|
|
|
|
|
});
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2023-01-08 08:35:40 +00:00
|
|
|
const game = gameResponse?.games[0];
|
|
|
|
|
game.players = `${game.min_players}-${game.max_players}`;
|
|
|
|
|
game.playtime = `${game.min_playtime}-${game.max_playtime}`;
|
|
|
|
|
|
2022-12-25 18:52:36 +00:00
|
|
|
return {
|
2023-01-08 08:35:40 +00:00
|
|
|
game
|
2022-12-25 18:52:36 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-04-20 02:15:46 +00:00
|
|
|
|
2022-12-25 18:52:36 +00:00
|
|
|
throw error(response.status, 'not found');
|
2022-07-28 00:05:54 +00:00
|
|
|
};
|