Orders list for the ops dashboard

Node · Node · intermediate · greenfield

Adds the orders endpoint for the ops dashboard: fetches the 50 most recent orders and enriches each with the customer's name and email. Tested locally, responses look complete.

Production: ~200k orders, ~40k customers in Postgres. Every open dashboard polls this endpoint every 30 seconds.

Requirements

Files touched

--- src/routes/orders.js
+const express = require("express");
+const db = require("../lib/db");
+
+const router = express.Router();
+
+router.get("/orders", async (req, res) => {
+  const orders = await db.orders.findRecent(50);
+  for (const order of orders) {
+    const customer = await db.customers.findById(order.customerId);
+    order.customerName = customer.name;
+    order.customerEmail = customer.email;
+  }
+  res.json(orders);
+});
+
+module.exports = router;

Review this PR

Node practice