Refactor AdventureCard component and add new adventure page
This commit is contained in:
32
src/routes/adventure/[id]/+page.server.ts
Normal file
32
src/routes/adventure/[id]/+page.server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
|
||||
export const load = (async (event) => {
|
||||
if (!event.locals.user) {
|
||||
return redirect(302, "/login");
|
||||
}
|
||||
|
||||
let adventureUserId = await db
|
||||
.select({ userId: adventureTable.userId })
|
||||
.from(adventureTable)
|
||||
.where(eq(adventureTable.id, Number(event.params.id)))
|
||||
.limit(1)
|
||||
.execute();
|
||||
|
||||
console.log(adventureUserId);
|
||||
|
||||
if (
|
||||
adventureUserId &&
|
||||
adventureUserId[0]?.userId !== event.locals.user.id &&
|
||||
adventureUserId !== null
|
||||
) {
|
||||
return redirect(302, "/log");
|
||||
}
|
||||
|
||||
let adventure = await event.fetch(`/api/adventure?id=${event.params.id}`);
|
||||
|
||||
return { adventure: await adventure.json() };
|
||||
}) satisfies PageServerLoad;
|
||||
Reference in New Issue
Block a user