import { calcFullName } from '../../shared/fullname.pipe' ; import { OrderGraph } from '../services' ; /**  Order ViewModel: the "graph" of Order/LineItems/Products */ export interface OrderVm { orderId : number ; customerName : string ; memo : string ; orderDate : Date ; lineItems : LineItemVm [ ] ; } /** ViewModel of an individual order line-item */ export interface LineItemVm { id : number ; productId : number ; productName : string ; price : number ; quantity : number ; } /** Creates an Order ViewModel from customer and order graph */ export function createOrderVm ( customer , orderGraph ) { const { order , lineItems , products } = orderGraph ; const lineItemVms = lineItems . map ( item => { const { productName , price } = products [ item . productId ] ; const lineItemVm = { id : item . id , productId : item . productId , productName , price , quantity : item . quantity } ; return lineItemVm ; } ) ; const orderVm = { orderId : order . id , customerName : calcFullName ( customer ) , memo : order . memo , orderDate : order . orderDate , lineItems : lineItemVms } ; return orderVm ; }