okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-142c-small into f-142407ea8192

main
560 B16 linesraw
1import type { Order, Summary } from './orders.ts';
2
3export function aggregateOrders(orders: Order[]): Summary[] {
4  const groups = new Map<string, Summary>();
5  for (const o of orders) {
6    if (o.cancelled) continue;
7    let s = groups.get(o.customer);
8    if (!s) {
9      s = { customer: o.customer, totalCents: 0, units: 0 };
10      groups.set(o.customer, s);
11    }
12    s.totalCents += o.priceCents * o.quantity;
13    s.units += o.quantity;
14  }
15  return [...groups.values()].sort((a, b) => (a.customer < b.customer ? -1 : a.customer > b.customer ? 1 : 0));
16}