okami.mom/strata

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

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

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