chore: Add tripId field to Adventure interface and schema

This commit is contained in:
Sean Morley
2024-05-15 21:06:01 +00:00
parent a0400bca8e
commit b94fdc7107
6 changed files with 544 additions and 3 deletions

View File

@@ -91,7 +91,6 @@ export const userPlannedTrips = pgTable("userPlannedTrips", {
description: text("description"),
startDate: text("startDate"),
endDate: text("endDate"),
adventures: json("adventures"),
});
export const adventureTable = pgTable("adventures", {
@@ -106,4 +105,5 @@ export const adventureTable = pgTable("adventures", {
link: text("link"),
imageUrl: text("imageUrl"),
date: text("date"),
tripId: integer("tripId").references(() => userPlannedTrips.id),
});

View File

@@ -9,6 +9,7 @@ export interface Adventure {
link?: string | undefined;
imageUrl?: string | undefined;
date?: string | undefined;
tripId?: number | undefined;
}
export interface Trip {

View File

@@ -2,7 +2,7 @@ import { lucia } from "$lib/server/auth";
import { error, type RequestEvent } from "@sveltejs/kit";
import { adventureTable } from "$lib/db/schema";
import { db } from "$lib/db/db.server";
import { and, eq } from "drizzle-orm";
import { and, eq, isNull } from "drizzle-orm";
import type { Adventure } from "$lib/utils/types";
// Gets all the adventures that the user has visited
@@ -21,7 +21,8 @@ export async function GET(event: RequestEvent): Promise<Response> {
.where(
and(
eq(adventureTable.userId, event.locals.user.id),
eq(adventureTable.type, "planner")
eq(adventureTable.type, "planner"),
isNull(adventureTable.tripId)
)
)
.execute();