diff --git a/backend/database/src/index.ts b/backend/database/src/index.ts index 2968f4d..39349e0 100644 --- a/backend/database/src/index.ts +++ b/backend/database/src/index.ts @@ -21,38 +21,11 @@ export default { const db = drizzle(env.DB, { schema }); - if (path.startsWith("/api/user")) { - if (path === "/api/user") { - if (method === "GET") { - const params = url.searchParams; - - if (params.has("id")) { - const id = params.get("id") as string; - const res = await db.select().from(user).where(eq(user.id, id)).get(); - console.log(res); - return json(res ?? {}); - } else { - const res = await db.select().from(user).all(); - return json(res ?? {}); - } - } else if (method === "POST") { - const userSchema = z.object({ - id: z.string(), - name: z.string(), - email: z.string().email(), - }); - - const body = await request.json(); - const { id, name, email } = userSchema.parse(body); - - const res = await db.insert(user).values({ id, name, email }).returning().get(); - return json({ res }); - } else { - return new Response("Method Not Allowed", { status: 405 }); - } - } else if (path === "/api/user/sandbox") { + if (path === "/api/user") { + if (method === "GET") { const params = url.searchParams; - if (method === "GET" && params.has("id")) { + + if (params.has("id")) { const id = params.get("id") as string; const res = await db.query.user.findFirst({ where: (user, { eq }) => eq(user.id, id), @@ -62,10 +35,23 @@ export default { }); return json(res ?? {}); } else { - return new Response("Method Not Allowed", { status: 405 }); + const res = await db.select().from(user).all(); + return json(res ?? {}); } + } else if (method === "POST") { + const userSchema = z.object({ + id: z.string(), + name: z.string(), + email: z.string().email(), + }); + + const body = await request.json(); + const { id, name, email } = userSchema.parse(body); + + const res = await db.insert(user).values({ id, name, email }).returning().get(); + return json({ res }); } else { - return new Response("Not Found", { status: 404 }); + return new Response("Method Not Allowed", { status: 405 }); } } else return new Response("Not Found", { status: 404 }); }, diff --git a/frontend/app/(app)/dashboard/page.tsx b/frontend/app/(app)/dashboard/page.tsx index 467d1c7..e2db8a6 100644 --- a/frontend/app/(app)/dashboard/page.tsx +++ b/frontend/app/(app)/dashboard/page.tsx @@ -2,7 +2,7 @@ import { UserButton, currentUser } from "@clerk/nextjs" import { redirect } from "next/navigation" import Dashboard from "@/components/dashboard" import Navbar from "@/components/dashboard/navbar" -import { Sandbox } from "@/lib/types" +import { Sandbox, User } from "@/lib/types" export default async function DashboardPage() { const user = await currentUser() @@ -11,17 +11,13 @@ export default async function DashboardPage() { redirect("/") } - const res = await fetch( - `http://localhost:8787/api/user/sandbox?id=${user.id}` - ) - const data = (await res.json()).sandbox as Sandbox[] - - console.log(data) + const userRes = await fetch(`http://localhost:8787/api/user?id=${user.id}`) + const userData = (await userRes.json()) as User return (