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