在这段生成的订单报告函数处理生产数据前,对它进行审查。
获取客户信息,汇总每笔订单,按总额降序排列,并返回安全的 HTML 列表,同时不能压垮客户服务。
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('');
}
生成代码仅作示例,不代表任何特定模型