Refactor adventure page layout to display activity types in +page.svelte and update server files

This commit is contained in:
Sean Morley
2024-04-30 22:52:07 +00:00
parent 296659ea27
commit 9f9f0c3d87
2 changed files with 24 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import { db } from "$lib/db/db.server";
import { adventureTable } from "$lib/db/schema";
import type { Adventure } from "$lib/utils/types";
import { json, type RequestEvent, type RequestHandler } from "@sveltejs/kit";
import { and, eq } from "drizzle-orm";
@@ -38,6 +39,20 @@ export const GET: RequestHandler = async ({ url, locals }) => {
return json({ error: "Adventure not found" }, { status: 404 });
}
let adventureData = JSON.stringify(
adventure.map((r) => {
const adventure: Adventure = r as Adventure;
if (typeof adventure.activityTypes === "string") {
try {
adventure.activityTypes = JSON.parse(adventure.activityTypes);
} catch (error) {
console.error("Error parsing activityTypes:", error);
adventure.activityTypes = undefined;
}
}
})
);
// console.log("GET /api/adventure?id=", id);
// console.log("User:", user);