Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions examples/api/orders/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ export async function POST(req: Request) {
return NextResponse.json({ error: "Too many requests" }, { status: 429 });
}

let body: unknown;
try {
body = await req.json();
} catch {
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
}
const body = await req.json();

const parsed = CreateOrderSchema.safeParse(body);
if (!parsed.success) {
Expand All @@ -34,7 +29,7 @@ export async function POST(req: Request) {
const { productId, quantity, couponCode } = parsed.data;

const product = await db.product.findUnique({ where: { id: productId } });
if (!product || product.stock < quantity) {
if (!product) {
return NextResponse.json({ error: "Out of stock" }, { status: 409 });
}

Expand Down
Loading