Refactor CreateNewAdventure component to add activity types and update server files
This commit is contained in:
@@ -22,7 +22,20 @@ export async function GET(event: RequestEvent): Promise<Response> {
|
||||
.execute();
|
||||
return new Response(
|
||||
// turn the result into an Adventure object array
|
||||
JSON.stringify(result.map((r) => r as Adventure)),
|
||||
JSON.stringify(
|
||||
result.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;
|
||||
}
|
||||
}
|
||||
return adventure;
|
||||
})
|
||||
),
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
@@ -86,7 +99,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||
|
||||
const { newAdventure } = await event.request.json();
|
||||
console.log(newAdventure);
|
||||
const { name, location, date, description } = newAdventure;
|
||||
const { name, location, date, description, activityTypes } = newAdventure;
|
||||
|
||||
if (!name) {
|
||||
return error(400, {
|
||||
@@ -94,6 +107,8 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||
});
|
||||
}
|
||||
|
||||
console.log(activityTypes);
|
||||
|
||||
// insert the adventure to the user's visited list
|
||||
let res = await db
|
||||
.insert(adventureTable)
|
||||
@@ -104,6 +119,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||
location: location || null,
|
||||
date: date || null,
|
||||
description: description || null,
|
||||
activityTypes: JSON.stringify(activityTypes) || null,
|
||||
})
|
||||
.returning({ insertedId: adventureTable.id })
|
||||
.execute();
|
||||
|
||||
@@ -8,7 +8,6 @@ export const load: PageServerLoad = async (event) => {
|
||||
}
|
||||
const response = await event.fetch("/api/visits");
|
||||
const result = await response.json();
|
||||
// let array = result.adventures as Adventure[];
|
||||
return {
|
||||
result,
|
||||
};
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
date: event.detail.date,
|
||||
description: event.detail.description,
|
||||
id: -1,
|
||||
activityTypes: event.detail.activityTypes,
|
||||
};
|
||||
|
||||
fetch("/api/visits", {
|
||||
@@ -123,6 +124,7 @@
|
||||
date: event.detail.date,
|
||||
id: event.detail.id,
|
||||
description: event.detail.description,
|
||||
activityTypes: event.detail.activityTypes,
|
||||
};
|
||||
|
||||
// put request to /api/visits with id and advneture data
|
||||
|
||||
Reference in New Issue
Block a user