import { Observable } from 'rxjs/Observable' ; import { Subject } from 'rxjs/Subject' ; import { esIndex } from './consts' ; import { Injectable , Inject } from "@angular/core" ; /**
 * Data abstraction layer is an absraction to some connector (for now realized  FirebaseConnector , but you can create your own using this contract).
 * To use some connector you must provide it in app.module.ts
 * ```
 * providers: [
 *  ...,
 *  {
 *    provide: 'Connector'
 *    useClass: FirebaseConnector
 *  }
 * ]
 * ```
 * There are method with queryObject parameter.  ProductService use them to work with products. Query object are generated in this service.
  @ Injectable ( ) export class DbAbstractionLayer { constructor ( @ Inject ( 'Connector' ) private connector ) { } param { FormGroup } generalCategoryForm addGeneralCategory ( generalCategoryForm ) { this . connector . addGeneralCategory ( generalCategoryForm ) ; } param { FormGroup } categoryForm addCategory ( categoryForm ) { this . connector . addCategory ( categoryForm ) ; } param { FormGroup } attributeForm param { string } categoryId addAttribute ( attributeForm , categoryId ) { this . connector . addAttribute ( attributeForm , categoryId ) ; } param { FormGroup } tagForm param { string } categoryId addTag ( tagForm , categoryId ) { this . connector . addTag ( tagForm , categoryId ) ; } param { Object } product addProduct ( product ) { this . connector . addProduct ( product ) ; } /**
     * Returns products by query object (look to  ProductService method getProductsByIds)
      getProductsByIds ( queryObj ) { return this . connector . requestFullData ( esIndex , 'product' , queryObj ) ; } param { string } userId returns { Observable } getBasketContent ( id ) { return this . connector . getBasketContent ( id ) ; } param { string } userId initializeBasketHistory ( userId ) { return this . connector . initializeBasketHistory ( userId ) ; } returns { Subject } getBasketHistorySubject ( ) { return this . connector . getBasketHistorySubject ( ) ; } param { string } userId returns { Observable } getBasketHistoryById ( id ) { return this . connector . getBasketHistoryById ( id ) ; } /**
     * Will be realized in next versions
     */ getСomparison ( id ) { return this . connector . getComparison ( id ) ; } param id param newBasket setNewBasket ( id , newBasket ) { return this . connector . setNewBasket ( id , newBasket ) ; } /**
     * Will be realized in next versions
     */ addProductToComparison ( id , product ) { return this . connector . addProductToComparison ( id , product ) ; } /**
     * Will be realized in next versions
     */ removeProductFromComparison ( id , idInComparison ) { return this . connector . removeProductFromComparison ( id , idInComparison ) ; } param { string } index param { string } type param { Object } queryObj returns { Observable } requestData ( esIndex , type , queryObj ) { return this . connector . requestData ( esIndex , type , queryObj ) ; } param { string } index param { string } type param { Object } queryObj returns { Observable } requestFullData ( esIndex , type , queryObj ) { return this . connector . requestFullData ( esIndex , type , queryObj ) ; } param { string } index param { string } type param { Object } queryObj returns { Observable } requestItemsTotal ( esIndex , type , queryObj ) { return this . connector . requestItemsTotal ( esIndex , 'product' , queryObj ) ; } param { Object } queryObj returns { Observable } getTags ( queryObj ) { return this . connector . requestData ( esIndex , 'tags' , queryObj ) ; } param { Object } queryObj returns { Observable } getAttributes ( queryObj ) { return this . connector . requestFullData ( esIndex , 'attributes' , queryObj ) ; } /**
     * Logout user
     */ logout ( ) { this . connector . logout ( ) ; } param { string } email param { string } password returns register ( email , password ) { return this . connector . register ( email , password ) ; } param registerForm registerUser ( registerForm ) { return this . connector . registerUser ( registerForm ) ; } param { string } uid returns { Observable } getUserData ( uid ) { return this . connector . getUserData ( uid ) ; } param { string } email param { string } password returns loginEmail ( email , password ) { return this . connector . loginEmail ( email , password ) ; } param { string } deviceId checkOldSessionFlow ( deviceId ) { this . connector . checkOldSessionFlow ( deviceId ) ; } /**
     * Connect [Session-flow] https to databese.
     *
     *  param { SessionFlow } sessionFlow param { string } deviceId param { string } sessionId connectSessionFlowToDB ( sessionFlow , deviceId , sessionId ) { this . connector . connectSessionFlowToDB ( sessionFlow , deviceId , sessionId ) ; } returns getVisitedRoutes ( ) { return this . connector . getVisitedRoutes ( ) ; } returns getUserClicks ( ) { return this . connector . getUserClicks ( ) ; } returns getAuth ( ) { return this . connector . getAuth ( ) ; } param { Object } paymentData returns { Observable } saveOrder ( orderData ) { return this . connector . saveOrder ( orderData ) ; } param { Object } data param { string } paymentMethod returns { Observable } addPaymentRequest ( data , paymentMethod ) { return this . connector . addPaymentRequest ( data , paymentMethod ) ; } param { string } paymentKey returns { Observable } listenPaymentResponse ( paymentKey ) { return this . connector . listenPaymentResponse ( paymentKey ) ; } param { string } userId returns { Observable } getOrdersByUserId ( userId ) { let queryObj = { query : { multi_match : { query : userId , fields : [ "orderForm.userId" ] , type : "phrase" } } } ; console . log ( queryObj ) ; return this . connector . requestFullData ( esIndex , 'orders' , queryObj ) ; } param { string } email returns resetPassword ( email ) { return this . connector . resetPassword ( email ) ; } param id returns { Observable } getOrderById ( id ) { return this . connector . getOrderById ( id ) ; } returns { Observable } listenOrders ( ) { return this . connector . listenOrders ( ) ; } getOrderSubject ( ) { return this . connector . getOrderSubject ( ) ; } getSeoText ( url , indexBlock ) { return this . connector . getSeoText ( url , indexBlock ) ; } }