diff --git a/apps/nextjs/src/app/api/products/route.ts b/apps/nextjs/src/app/api/products/route.ts deleted file mode 100644 index e7dc069..0000000 --- a/apps/nextjs/src/app/api/products/route.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { NextResponse } from "next/server"; -import { revalidatePath } from "next/cache"; -import { z } from "zod"; - -import { - createProduct, - deleteProduct, - updateProduct, -} from "@/lib/api/products/mutations"; -import { - productIdSchema, - insertProductParams, - updateProductParams -} from "@/server/db/schema/products"; - -export async function POST(req: Request) { - try { - const validatedData = insertProductParams.parse(await req.json()); - const { success, error } = await createProduct(validatedData); - if (error) return NextResponse.json({ error }, { status: 500 }); - revalidatePath("/products"); // optional - assumes you will have named route same as entity - return NextResponse.json(success, { status: 201 }); - } catch (err) { - if (err instanceof z.ZodError) { - return NextResponse.json({ error: err.issues }, { status: 400 }); - } else { - return NextResponse.json({ error: err }, { status: 500 }); - } - } -} - - -export async function PUT(req: Request) { - try { - const { searchParams } = new URL(req.url); - const id = searchParams.get("id"); - - const validatedData = updateProductParams.parse(await req.json()); - const validatedParams = productIdSchema.parse({ id }); - - const { success, error } = await updateProduct(validatedParams.id, validatedData); - - if (error) return NextResponse.json({ error }, { status: 500 }); - return NextResponse.json(success, { status: 200 }); - } catch (err) { - if (err instanceof z.ZodError) { - return NextResponse.json({ error: err.issues }, { status: 400 }); - } else { - return NextResponse.json(err, { status: 500 }); - } - } -} - -export async function DELETE(req: Request) { - try { - const { searchParams } = new URL(req.url); - const id = searchParams.get("id"); - - const validatedParams = productIdSchema.parse({ id }); - const { success, error } = await deleteProduct(validatedParams.id); - if (error) return NextResponse.json({ error }, { status: 500 }); - - return NextResponse.json(success, { status: 200 }); - } catch (err) { - if (err instanceof z.ZodError) { - return NextResponse.json({ error: err.issues }, { status: 400 }); - } else { - return NextResponse.json(err, { status: 500 }); - } - } -} diff --git a/apps/nextjs/src/app/api/webhook/route.ts b/apps/nextjs/src/app/api/webhook/route.ts index 401b84a..ba4f590 100644 --- a/apps/nextjs/src/app/api/webhook/route.ts +++ b/apps/nextjs/src/app/api/webhook/route.ts @@ -3,7 +3,7 @@ import type { User } from "@clerk/nextjs/api"; import { Webhook } from "svix"; import { db, eq } from "@vivat/db"; -import { users } from "@vivat/db/schema/user"; +import { users } from "@vivat/db/schema/users"; type UnwantedKeys = | "emailAddresses" diff --git a/packages/db/schema/products.ts b/packages/db/schema/products.ts index fa7a52c..6d87a2f 100644 --- a/packages/db/schema/products.ts +++ b/packages/db/schema/products.ts @@ -20,7 +20,7 @@ export const products = mySqlTable( stock: int("stock").notNull(), image: varchar("image", { length: 256 }).notNull(), sellerId: varchar("seller_id", { length: 36 }).notNull(), - categoryId: varchar("category", { length: 255 }).notNull(), + categoryId: varchar("category_id", { length: 255 }).notNull(), createdAt: timestamp("created_at") .default(sql`CURRENT_TIMESTAMP`) .notNull(),