30 lines
777 B
TypeScript
30 lines
777 B
TypeScript
|
|
import { getAdventureBffAdventureAdventureIdGet } from '@client';
|
||
|
|
import type { PageServerLoad } from './$types';
|
||
|
|
import { error } from '@sveltejs/kit';
|
||
|
|
|
||
|
|
export const load: PageServerLoad = async ({ locals, params }) => {
|
||
|
|
const response = await getAdventureBffAdventureAdventureIdGet({
|
||
|
|
path: {
|
||
|
|
adventure_id: params.id
|
||
|
|
},
|
||
|
|
headers: {
|
||
|
|
Authorization: `Bearer ${locals.authToken}`
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
if (response.error) {
|
||
|
|
console.error(`Error fetching an adventure:`);
|
||
|
|
console.error({ error: response.error });
|
||
|
|
return error(400, `Error loading adventure`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const { title, entries, current_entry_choices } = response.data;
|
||
|
|
|
||
|
|
response.data.entries.forEach((e) => console.log(e.story_text));
|
||
|
|
return {
|
||
|
|
title: title,
|
||
|
|
entries,
|
||
|
|
choices: current_entry_choices
|
||
|
|
};
|
||
|
|
};
|