Refactor AdventureCard component and shared page

This commit is contained in:
Sean Morley
2024-04-11 21:15:34 +00:00
parent af07ea29ef
commit 167080441a
4 changed files with 76 additions and 6 deletions

View File

@@ -5,14 +5,33 @@ import type { Adventure } from "$lib/utils/types";
export async function load({ params }) {
let key = params.key;
// Fetch data from the database
let result = await db
.select()
.from(sharedAdventures)
.where(eq(sharedAdventures.id, key))
.execute();
let adventure = result[0].data as Adventure;
console.log(adventure);
// Assuming result is an array with a single object
let rawData = result[0];
// Parse the data field, which contains a JSON string
let adventures = JSON.parse(rawData.data as string);
// Map the parsed adventures to the Adventure interface
let adventureArray = adventures.map((item: any) => {
return {
id: item.id,
name: item.name,
location: item.location,
created: item.created,
} as Adventure;
});
// Return the array of Adventure objects
return {
result: adventure,
adventureArray,
};
}