mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 12:45:17 +02:00
chore: Refactor trip API endpoint to include adventures
This commit is contained in:
parent
126a256253
commit
f8f12e4ba3
1 changed files with 25 additions and 2 deletions
|
@ -22,7 +22,7 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||||
return json({ error: "Missing adventure ID" }, { status: 400 });
|
return json({ error: "Missing adventure ID" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const trip = await db
|
let trip = await db
|
||||||
.select()
|
.select()
|
||||||
.from(userPlannedTrips)
|
.from(userPlannedTrips)
|
||||||
.where(
|
.where(
|
||||||
|
@ -38,14 +38,37 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||||
return json({ error: "Trip not found" }, { status: 404 });
|
return json({ error: "Trip not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let adventures = await db
|
||||||
|
.select()
|
||||||
|
.from(adventureTable)
|
||||||
|
.where(eq(adventureTable.tripId, trip[0].id))
|
||||||
|
.execute();
|
||||||
|
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
trip.map((r) => {
|
trip.map((r) => {
|
||||||
const adventure: Trip = r as Trip;
|
const adventure: Trip = r as Trip;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (adventures.length !== 0) {
|
||||||
|
JSON.stringify(
|
||||||
|
adventures.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;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// console.log("GET /api/adventure?id=", id);
|
// console.log("GET /api/adventure?id=", id);
|
||||||
// console.log("User:", user);
|
// console.log("User:", user);
|
||||||
|
|
||||||
return json({ trip }, { status: 200 });
|
return json({ trip, adventures }, { status: 200 });
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue