import { Injectable } from '@angular/core' ; import { InMemoryDbService , RequestInfo , STATUS , } from 'angular-in-memory-web-api' ; import { DaffInMemoryDataServiceInterface } from '@daffodil/core/testing' ; import { DaffOrder } from '@daffodil/order' ; import { DaffOrderFactory } from '@daffodil/order/testing' ; inheritdoc @ Injectable ( { providedIn : 'root' , } ) export class DaffInMemoryBackendOrderService implements InMemoryDbService , DaffInMemoryDataServiceInterface { orders : DaffOrder [ ] ; constructor ( private orderFactory ) { this . orders = this . orderFactory . createMany ( 5 ) ; } docs-private returns createDb ( reqInfo ) { if ( reqInfo ) { const seedData = reqInfo . utils . getJsonBody ( reqInfo . req ) . orders ; if ( seedData ) { this . orders = seedData ; } } return { orders : this . orders , } ; } /**
     * Responds to GET requests.
     */ get ( reqInfo ) { return reqInfo . utils . createResponse$ ( ( ) => ( { body : reqInfo . id ? this . getOrder ( reqInfo ) : this . listOrders ( reqInfo ) , status : STATUS . OK , } ) ) ; } private getOrder ( reqInfo ) { return reqInfo . collection . find ( order => order . id === reqInfo . id ) ; } private listOrders ( reqInfo ) { return reqInfo . collection ; } }