language-learning-app/frontend/src/routes/app/adventures/[id]/+page.server.ts

31 lines
769 B
TypeScript
Raw Normal View History

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, language, status } = response.data;
return {
title: title,
entries,
choices: current_entry_choices,
language: language,
status: status
};
};