import { Injectable } from '@angular/core' ; import { InMemoryDbService , STATUS , } from 'angular-in-memory-web-api' ; import { DaffProductImageFactory } from '@daffodil/product/testing' ; import { DaffOrderItemFactory } from '../order/factories/order-item.factory' ; import { DaffOrderFactory } from '../order/factories/order.factory' ; @ Injectable ( { providedIn : 'root' , } ) export class DaffInMemoryBackendCheckoutService implements InMemoryDbService { private order ; constructor ( private orderFactory , private orderItemFactory , private productImageFactory ) { } post ( reqInfo ) { return reqInfo . utils . createResponse$ ( ( ) => { if ( reqInfo . id === 'placeOrder' ) { this . populateOrder ( ) ; } return { body : this . order , status : STATUS . OK , } ; } ) ; } createDb ( ) { return { order : null , } ; } private populateOrder ( ) { this . order = this . orderFactory . create ( { items : this . orderItemFactory . createMany ( 2 , { image : this . productImageFactory . create ( ) , } ) , } ) ; } }