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