Add an order details endpoint

Node · Node · intermediate · greenfield

Adds the order details endpoint. Pulls the order by its id from the database and returns it, with a 404 when there's no such row. requireAuth already guards the route, so only logged-in users can reach it. Verified against seeded orders and the 404 path.

This is the customer-facing store API on the public internet; order ids are sequential integers visible in URLs and emails.

Requirements

Files touched

--- src/routes/orders.js
+router.get('/orders/:id', requireAuth, async (req, res) => {
+  const order = await db.orders.findById(req.params.id);
+  if (!order) {
+    return res.status(404).json({ error: 'Order not found' });
+  }
+  return res.json(order);
+});

Review this PR

Node practice