Review a generated order report

from Array methods
Node 24 advanced 6 min 4 issues to find

Review this generated order-report function before it handles production data.

Fetch customers, total each order, sort highest totals first, and return a safe HTML list without overrunning the customer service.

JavaScript
async function renderOrderReport(orders) {
  const rows = await Promise.all(
    orders.map(async (order) => {
      const customer = await fetchCustomer(order.customerId);
      const total = order.lines
        .map((line) => line.price * line.quantity)
        .reduce((sum, value) => sum + value);
      return { customer: customer.name, total };
    }),
  );

  rows.sort((a, b) => a.total < b.total);
  return rows
    .map((row) => `<li>${row.customer}: ${row.total}</li>`)
    .join('');
}

generated code is illustrative, not from any one model

Open in playground
Report an error