import { Injectable } from '@angular/core' ; import { InMemoryDbService , RequestInfo , STATUS , } from 'angular-in-memory-web-api' ; import { DaffInMemoryDataServiceInterface } from '@daffodil/core/testing' ; import { DaffCountry } from '@daffodil/geography' ; import { DaffCountryFactory , DaffSubdivisionFactory , } from '@daffodil/geography/testing' ; inheritdoc @ Injectable ( { providedIn : 'root' , } ) export class DaffInMemoryBackendGeographyService implements InMemoryDbService , DaffInMemoryDataServiceInterface { countries : DaffCountry [ ] ; constructor ( private countryFactory , private subdivisionFactory ) { this . countries = this . countryFactory . createMany ( 5 ) ; this . countries . forEach ( country => country . subdivisions = this . subdivisionFactory . createMany ( 5 ) ) ; } docs-private returns createDb ( reqInfo ) { if ( reqInfo ) { const seedData = reqInfo . utils . getJsonBody ( reqInfo . req ) . countries ; if ( seedData ) { this . countries = seedData ; } } return { countries : this . countries , } ; } /**
     * Responds to GET requests.
     */ get ( reqInfo ) { return reqInfo . utils . createResponse$ ( ( ) => ( { body : reqInfo . id ? this . getCountry ( reqInfo ) : this . listCountries ( reqInfo ) , status : STATUS . OK , } ) ) ; } private getCountry ( reqInfo ) { return reqInfo . collection . find ( country => country . id === reqInfo . id ) ; } private listCountries ( reqInfo ) { return reqInfo . collection ; } }