import { Injectable } from '@angular/core' ; import { Dictionary } from '@ngrx/entity' ; import { Action , Store , select , } from '@ngrx/store' ; import { Observable } from 'rxjs' ; import { DaffStateError } from '@daffodil/core/state' ; import { DaffOrder , DaffOrderTotal , } from '@daffodil/order' ; import { DaffOrderStateRootSlice } from '../../reducers/public_api' ; import { DaffOrderEntitySelectors } from '../../selectors/order-entities.selector' ; import { getDaffOrderSelectors } from '../../selectors/public_api' ; import { DaffOrderFacadeInterface } from './order-facade.interface' ; inheritdoc @ Injectable ( { providedIn : 'root' , } ) export class DaffOrderFacade < T extends DaffOrder = DaffOrder > implements DaffOrderFacadeInterface < T > { loading$ : Observable < boolean > ; errors$ : Observable < DaffStateError [ ] > ; orders$ : Observable < T [ ] > ; orderIds$ : Observable < T [ 'id' ] [ ] > ; orderCount$ : Observable < number > ; orderEntities$ : Observable < Dictionary < T > > ; placedOrder$ : Observable < T > ; hasPlacedOrder$ : Observable < boolean > ; _order : DaffOrderEntitySelectors < T > [ 'selectOrder' ] ; _totals : DaffOrderEntitySelectors < T > [ 'selectOrderTotals' ] ; _appliedCodes : DaffOrderEntitySelectors < T > [ 'selectOrderAppliedCodes' ] ; _items : DaffOrderEntitySelectors < T > [ 'selectOrderItems' ] ; _billingAddresses : DaffOrderEntitySelectors < T > [ 'selectOrderBillingAddresses' ] ; _shippingAddresses : DaffOrderEntitySelectors < T > [ 'selectOrderShippingTotalAddresses' ] ; _shipments : DaffOrderEntitySelectors < T > [ 'selectOrderShipments' ] ; _payment : DaffOrderEntitySelectors < T > [ 'selectOrderPayment' ] ; _invoices : DaffOrderEntitySelectors < T > [ 'selectOrderInvoices' ] ; _credits : DaffOrderEntitySelectors < T > [ 'selectOrderCredits' ] ; _grandTotal : DaffOrderEntitySelectors < T > [ 'selectOrderGrandTotal' ] ; _subtotal : DaffOrderEntitySelectors < T > [ 'selectOrderSubtotal' ] ; _shipping : DaffOrderEntitySelectors < T > [ 'selectOrderShippingTotal' ] ; _discount : DaffOrderEntitySelectors < T > [ 'selectOrderDiscountTotal' ] ; _hasDiscount : DaffOrderEntitySelectors < T > [ 'selectOrderHasDiscount' ] ; _tax : DaffOrderEntitySelectors < T > [ 'selectOrderTaxTotal' ] ; constructor ( private store ) { const { selectOrderIds , selectOrderEntities , selectAllOrders , selectOrderTotal , selectOrderLoading , selectOrderErrors , selectPlacedOrder , selectHasPlacedOrder , selectOrder , selectOrderTotals , selectOrderAppliedCodes , selectOrderItems , selectOrderBillingAddresses , selectOrderShippingTotalAddresses , selectOrderShipments , selectOrderPayment , selectOrderInvoices , selectOrderCredits , selectOrderGrandTotal , selectOrderSubtotal , selectOrderShippingTotal , selectOrderDiscountTotal , selectOrderHasDiscount , selectOrderTaxTotal , } = getDaffOrderSelectors < T > ( ) ; this . loading$ = this . store . pipe ( select ( selectOrderLoading ) ) ; this . errors$ = this . store . pipe ( select ( selectOrderErrors ) ) ; this . orders$ = this . store . pipe ( select ( selectAllOrders ) ) ; this . orderIds$ = this . store . pipe ( select ( selectOrderIds ) ) ; this . orderCount$ = this . store . pipe ( select ( selectOrderTotal ) ) ; this . orderEntities$ = this . store . pipe ( select ( selectOrderEntities ) ) ; this . placedOrder$ = this . store . pipe ( select ( selectPlacedOrder ) ) ; this . hasPlacedOrder$ = this . store . pipe ( select ( selectHasPlacedOrder ) ) ; this . _order = selectOrder ; this . _totals = selectOrderTotals ; this . _appliedCodes = selectOrderAppliedCodes ; this . _items = selectOrderItems ; this . _billingAddresses = selectOrderBillingAddresses ; this . _shippingAddresses = selectOrderShippingTotalAddresses ; this . _shipments = selectOrderShipments ; this . _payment = selectOrderPayment ; this . _invoices = selectOrderInvoices ; this . _credits = selectOrderCredits ; this . _grandTotal = selectOrderGrandTotal ; this . _subtotal = selectOrderSubtotal ; this . _shipping = selectOrderShippingTotal ; this . _discount = selectOrderDiscountTotal ; this . _hasDiscount = selectOrderHasDiscount ; this . _tax = selectOrderTaxTotal ; } getOrder$ ( orderId ) { return this . store . pipe ( select ( this . _order ( orderId ) ) ) ; } getTotals$ ( orderId ) { return this . store . pipe ( select ( this . _totals ( orderId ) ) ) ; } getAppliedCodes$ ( orderId ) { return this . store . pipe ( select ( this . _appliedCodes ( orderId ) ) ) ; } getItems$ ( orderId ) { return this . store . pipe ( select ( this . _items ( orderId ) ) ) ; } getBillingAddresses$ ( orderId ) { return this . store . pipe ( select ( this . _billingAddresses ( orderId ) ) ) ; } getShippingAddresses$ ( orderId ) { return this . store . pipe ( select ( this . _shippingAddresses ( orderId ) ) ) ; } getShipments$ ( orderId ) { return this . store . pipe ( select ( this . _shipments ( orderId ) ) ) ; } getPayment$ ( orderId ) { return this . store . pipe ( select ( this . _payment ( orderId ) ) ) ; } getInvoices$ ( orderId ) { return this . store . pipe ( select ( this . _invoices ( orderId ) ) ) ; } getCredits$ ( orderId ) { return this . store . pipe ( select ( this . _credits ( orderId ) ) ) ; } getGrandTotal$ ( orderId ) { return this . store . pipe ( select ( this . _grandTotal ( orderId ) ) ) ; } ; getSubtotal$ ( orderId ) { return this . store . pipe ( select ( this . _subtotal ( orderId ) ) ) ; } ; getShippingTotal$ ( orderId ) { return this . store . pipe ( select ( this . _shipping ( orderId ) ) ) ; } ; getDiscountTotal$ ( orderId ) { return this . store . pipe ( select ( this . _discount ( orderId ) ) ) ; } ; hasDiscount$ ( orderId ) { return this . store . pipe ( select ( this . _hasDiscount ( orderId ) ) ) ; } ; getTaxTotal$ ( orderId ) { return this . store . pipe ( select ( this . _tax ( orderId ) ) ) ; } ; dispatch ( action ) { this . store . dispatch ( action ) ; } }