import {catchError, map, tap} from 'rxjs/operators'; /** * @Service: Marketing Service * @Creation Date: Aug 3, 2017 * @Author: sbaireddy * @Version: 1.0 */ import { Injectable } from '@angular/core'; // import { Headers } from '@angular/http'; import { HttpClient } from '@angular/common/http'; // import { Observable } from 'rxjs/observable'; import { Observable } from 'rxjs/Rx'; // 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 { SharedService } from '../shared/shared.service'; /** * This class provides the Catalog Service with methods rateplan,device,feature and accessory list. */ @Injectable({providedIn:'root'}) export class MarketingService extends BaseService { gsmDevicesBanner: any; miDevicesBanner: any; accessoriesBanner: any; gsmDeviceSuggestions: any; miDeviceSuggestions: any; accessorySuggestions: any; getGSMDeviceSuggestions(storeId: number): any { if (this.gsmDeviceSuggestions) { return this.gsmDeviceSuggestions; } else { this.getEspotConfigContent(storeId, Constants.SUGGESTIONS_GSM_DEVICE).subscribe(result => { if (result) { this.gsmDeviceSuggestions = result; return this.gsmDeviceSuggestions; } }, error => { console.error('error=>' + error); }); } } getMIDeviceSuggestions(storeId: number): any { if (this.miDeviceSuggestions) { return this.miDeviceSuggestions; } else { this.getEspotConfigContent(storeId, Constants.SUGGESTIONS_MI_DEVICE).subscribe(result => { if (result) { this.miDeviceSuggestions = result; return this.miDeviceSuggestions; } }, error => { console.error('error=>' + error); }); } } getAccessorySuggestions(storeId: number): any { if (this.accessorySuggestions) { return this.accessorySuggestions; } else { this.getEspotConfigContent(storeId, Constants.SUGGESTIONS_ACCESSORY).subscribe(result => { if (result) { this.accessorySuggestions = result; return this.accessorySuggestions; } }, error => { console.error('error=>' + error); }); } } /** * Creates a new UserService with the injected HttpClient. * @param {HttpClient} _http - The injected HttpClient. * @constructor */ constructor(public _http: HttpClient) { super(); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return {any} The Observable for the HTTP request. */ getEspotStaticContent(storeId: number, espotName: string): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-marketingService.getEspotStaticContent()'); } // getting the request options let options = this.httpOptions(); // const headers = new Headers({ 'Content-Type': 'text/html' }); // const options = { headers: headers }; // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); pathParams.push(new KeyValue('espotName', espotName)); // getting the final url const url = Utils.replacePathParams(restUrl.catalog.getEspotStatic, pathParams); // service calling return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-marketingService.getEspotStaticContent()'); } }),// for debug catchError(this.handleError)); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return {any} The Observable for the HTTP request. */ getEspotConfigContent(storeId: number, espotName: string): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-marketingService.getEspotConfigContent()'); } // 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('espotName', espotName)); // getting the final url const url = Utils.replacePathParams(restUrl.catalog.getEspotConfig, pathParams); // service calling return this._http.get(url, options).pipe( map((res: any) => { if (res && res._body) { const suggestions = res._body.trim(); if (suggestions && suggestions.length > 0) { return JSON.parse(suggestions); } } }), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-marketingService.getEspotConfigContent()'); } }),// for debug catchError(this.handleError)); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return {any} The Observable for the HTTP request. */ sendQuote(storeId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-marketingService.sendQuote()'); } // 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)); // getting the final url const url = Utils.replacePathParams(restUrl.catalog.sendQuote, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-marketingService.sendQuote()'); } }), // for debug catchError(this.handleError)); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return {any} The Observable for the HTTP request. */ sendFeedback(storeId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-marketingService.sendFeedback()'); } // let headers = new Headers( { 'Content-Type': 'multipart/form-data','X-Atlassian-Token': 'nocheck', 'charset': 'UTF-8'}); // const headers = new Headers(); const options = this.httpOptions(); // let options = new RequestOptions( { headers: headers }); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue(ServiceConstants.STORE_ID, storeId)); // getting the final url const url = Utils.replacePathParams(restUrl.catalog.sendFeedback, pathParams); // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-marketingService.sendFeedback()'); } }), // for debug catchError(this.handleError)); } }