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
- Add GET /orders/:id that returns a single order as JSON.
- The route is mounted behind the existing requireAuth middleware, which sets req.userId from the session.
- Return 404 when the order does not exist.
Files touched
- src/routes/orders.js
--- 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);
+});