Skip to content

Commit 55e0b49

Browse files
committed
refactor(orders): simplify request parsing and stock check
1 parent 89ae5da commit 55e0b49

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

examples/api/orders/route.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ export async function POST(req: Request) {
1616
return NextResponse.json({ error: "Too many requests" }, { status: 429 });
1717
}
1818

19-
let body: unknown;
20-
try {
21-
body = await req.json();
22-
} catch {
23-
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
24-
}
19+
const body = await req.json();
2520

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

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

0 commit comments

Comments
 (0)