import {catchError, tap, map} from 'rxjs/operators'; import { Injectable } from '@angular/core'; // import { HttpClient, Headers, RequestOptions, Response } from '@angular/_http'; import { HttpClient } from '@angular/common/http'; // import { Observable } from 'rxjs/observable'; import { Observable } from 'rxjs/Rx'; // import { Subject } from 'rxjs/Subject'; // for debugging import { BaseService } from './base.service'; import * as ServiceConstants from '../shared/service.constants'; import * as Constants from '../shared/constants'; import Utils from '../shared/utils'; import { restUrl } from '../rest.url'; import { KeyValue } from '../shared/modal/key.value'; // import { IError } from '../shared/modal/common'; import { UserService } from '../services/user.service'; import { CartService } from '../services/cart.service'; import { CustomerService } from '../services/customer.service'; @Injectable({providedIn:'root'}) export class TradeinService extends BaseService { tradeInDevicesList: any; tradeInInfoList: any = []; tradeInDorminFlag: boolean = false; /** * Creates a new UserService with the injected HttpClient. * @param {HttpClient} _http - The injected HttpClient. * @constructor */ constructor( public _http: HttpClient, public userService: UserService, public cartService: CartService, public customerService: CustomerService ) { super(); } updateAdditionalHeaders(options: any): void { const user = this.userService.getUser().logonId; const customer = this.customerService.getCustomer(); const cart = this.cartService.getCart(); if (customer && customer.creditProfile && customer.creditProfile.accountNumber) { options.headers = options.headers.append('workflowid', 'ADDALINE'); } else { options.headers = options.headers.append('workflowid', 'Activation'); } if (cart && cart.dealerCode) { options.headers = options.headers.append('dealercode', (cart.dealerCode.length === 8) ? (cart.dealerCode.substr(1)) : cart.dealerCode); } else { options.headers = options.headers.append('dealercode', '0000000'); } options.headers = options.headers.append('applicationuserid', user); //const options = { headers: headers }; // console.log('Util.getRequestOptions()>>End'); //return options; // workflowid: Activation/ADD_A_LINE // applicationuserid: rverma2 // dealercode: 0000000 } /**Gets the tradeInDevice List */ getTradeInDevices(): any { if (this.tradeInDevicesList) { return this.tradeInDevicesList; } else { return Utils.getTradeInDeviceList(); } } getDorminFlag(): any { return this.tradeInDorminFlag; } /**Sets the master maufacture ,devices ,services list for */ setTradeInDevices(tradeInDevices: any): void { this.tradeInDevicesList = tradeInDevices; Utils.storeTradeInDeviceList(tradeInDevices); } saveTradeInInfo(orderItemId: number, tradeInInfo: any[]): void { if (orderItemId || (tradeInInfo && tradeInInfo.length > 0)) { if (tradeInInfo && tradeInInfo.length > 0) { this.tradeInInfoList = Utils.setOrderItemsIdTradeInInfo(this.tradeInInfoList, orderItemId, tradeInInfo); } else { this.tradeInInfoList.shift(orderItemId); } } else { this.tradeInInfoList = []; } } getTradeInInfo(): any { return this.tradeInInfoList; } updateTradeinList(tradeinList: any): void { this.tradeInInfoList = tradeinList; } // post addTradeIn(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.addTradeIn()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.addTradeIn, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.addTradeIn()'); } }),// for debug catchError(this.handleError)); } basicPromo(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.basicPromo()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.basicPromo, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.basicPromo()'); } }),// for debug catchError(this.handleError)); } eligibility(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.eligibility()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.eligibility, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.eligibility()'); } }),// for debug catchError(this.handleError)); } browsePromo(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.browsePromo()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.browsePromo, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( // return this._http.get('../assets/data/browsePromo.json', options) map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.promoSearch()'); } }),// for debug catchError(this.handleError)); } estimateQuote(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.getQuote()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.estimateQuote, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.getQuote()'); } }),// for debug catchError(this.handleError)); } searchQuotation(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.searchQuotation()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.searchQuotation, pathParams); // service calling // return this._http.get('../assets/data/searchQuotation.json', options) return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.searchQuotation()'); } }),// for debug catchError(this.handleError)); } // delete deleteTradeIn(storeId: number, orderId: number, orderItemId: number): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.deleteTradeIn()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.deleteTradeIn, pathParams); // service calling return this._http.delete(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.deleteTradeIn()'); } }),// for debug catchError(this.handleError)); } // put postQuote(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]--TradeInService.postQuote()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.postQuote, pathParams); // service calling return this._http.put(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.postQuote()'); } }),// for debug catchError(this.handleError)); } rmaCancel(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]--TradeInService.rmaCancel()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.rmaCancel, pathParams); // service calling return this._http.put(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.rmaCancel()'); } }),// for debug catchError(this.handleError)); } updateTradeIn(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.updateTradeIn()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.updateTradeIn, pathParams); // service calling return this._http.put(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.updateTradeIn()'); } }),// for debug catchError(this.handleError)); } // get byProgramType(storeId: number, orderId: number, orderItemId: number): Observable { const ProgramType = Constants.PROGRAM_TYPE_DRP; if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.byProgramType()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); pathParams.push(new KeyValue(ServiceConstants.PROGRAM_TYPE, ProgramType)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.byProgramType, pathParams); // service calling // return this._http.get('../assets/data/programtype.json', options) return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.byProgramType()'); } }),// for debug catchError(this.handleError)); } getItemTradeinInfo(storeId: number, orderId: number, orderItemId: number): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.getitemTradeinInfo()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.getItemTradeinInfo, pathParams); // service calling // return this._http.get('../assets/data/programtype.json', options) return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.getitemTradeinInfo()'); } }),// for debug catchError(this.handleError)); } getAllTradeinInfo(storeId: number, orderId: number): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.getAllTradeinInfo()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.getAllTradeinInfo, pathParams); // service calling // return this._http.get('../assets/data/programtype.json', options) return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.getAllTradeinInfo()'); } }),// for debug catchError(this.handleError)); } bySerialNumber(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.bySerialNumber()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // pathParams.push(new KeyValue(ServiceConstants.SERIAL_NUMBER, serialNumber)); // let queryParams: Array = new Array(); // if (programType) queryParams.push(new KeyValue('programType', programType)); // pathParams.push(new KeyValue(ServiceConstants.PROGRAM_TYPE, programType)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.bySerialNumber, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.bySerialNumber()'); } }),// for debug catchError(this.handleError)); } questions(storeId: number, orderId: number, orderItemId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-TradeInService.questions()'); } // getting the request options let options = this.httpOptions(); this.updateAdditionalHeaders(options); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ITEM_ID, orderItemId)); // getting the final url const queryParams: Array = new Array(); if (requestParams && requestParams.programType) { queryParams.push(new KeyValue('programType', requestParams.programType)); } if (requestParams && requestParams.manufacturer) { queryParams.push(new KeyValue('manufacturer', requestParams.manufacturer)); } if (requestParams && requestParams.model) { queryParams.push(new KeyValue('model', requestParams.model)); } if (requestParams && requestParams.serviceProvider) { queryParams.push(new KeyValue('serviceprovider', requestParams.serviceProvider)); } const url = Utils.replaceAppendParams(restUrl.tradein.questions, pathParams, queryParams); // service calling return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-TradeInService.questions()'); } }),// for debug catchError(this.handleError)); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return {IUsableShipping} The Observable for the HTTP request. */ generateToken(storeId: number, orderId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-CheckoutService.generateToken()'); } // getting the request options const options = this.httpOptions(); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue(ServiceConstants.ORDER_ID, orderId)); // getting the final url const url = Utils.replacePathParams(restUrl.tradein.generatetoken, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( // return this._http.get(url, options) map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-CheckoutService.getUsableShippingInfo()'); } }),// for debug catchError(this.handleError)); } }