chore: Add trip selection to AddFromFeatured component

This commit is contained in:
Sean Morley
2024-05-26 23:24:31 +00:00
parent 8888650c56
commit 4fd174530b
3 changed files with 73 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ import { db } from "$lib/db/db.server";
import { userPlannedTrips } from "$lib/db/schema";
import { error, type RequestEvent } from "@sveltejs/kit";
import { and, eq } from "drizzle-orm";
import type { Trip } from "$lib/utils/types";
export async function POST(event: RequestEvent): Promise<Response> {
if (!event.locals.user) {
@@ -37,7 +38,6 @@ export async function POST(event: RequestEvent): Promise<Response> {
description: description || null,
startDate: startDate || null,
endDate: endDate || null,
adventures: JSON.stringify([]),
})
.returning({ insertedId: userPlannedTrips.id })
.execute();
@@ -78,13 +78,6 @@ export async function GET(event: RequestEvent): Promise<Response> {
.where(eq(userPlannedTrips.userId, event.locals.user.id))
.execute();
// json parse the adventures into an Adventure array
for (let trip of trips) {
if (trip.adventures) {
trip.adventures = JSON.parse(trip.adventures as unknown as string);
}
}
return new Response(JSON.stringify(trips), {
status: 200,
headers: {