import {catchError, tap, map} from 'rxjs/operators'; /** * @Service:Lookup 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 Utils from '../shared/utils'; import { restUrl } from '../rest.url'; import { KeyValue } from '../shared/modal/key.value'; import { IOrderList } from '../shared/modal/common'; import { Customer } from '../shared/modal/customer'; import { Cart } from '../shared/modal/cart'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; /** * This class provides the Lookup Service with methods to lookup customer and orders. */ @Injectable({providedIn:'root'}) export class LookupService extends BaseService { orderSearchModel: any = null; orderList: IOrderList; order: Cart; public orderNotesIndicator: BehaviorSubject = new BehaviorSubject(null); /** * Creates a new UserService with the injected HttpClient. * @param { HttpClient} _http - The injected HttpClient. * @constructor */ constructor(public _http: HttpClient) { super(); } setOrderNotesIndicatorData(orderNotesIndicatorData: any) { this.orderNotesIndicator.next(orderNotesIndicatorData); } getOrderSearchModel(): any { return this.orderSearchModel; } setOrderSearchModel(orderSearchModel: any): void { this.orderSearchModel = orderSearchModel; } /**Gets the order search result */ getOrderList(): IOrderList { if (this.orderList) { return this.orderList; } else { return Utils.getOrderListDetails() } } /**Sets the order search result */ setOrderList(orderList: IOrderList): void { this.orderList = orderList; Utils.storeOrderListDetails(orderList); } /**Get cart details */ getOrder(): Cart { if (this.order) { return this.order; } else { return Utils.getOrderDetails() } } /**Get cart details*/ setOrder(order: Cart): void { this.order = order; Utils.storeOrderDetails(order); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return { Customer} The Observable for the HTTP request. */ lookupCustomer(storeId: number, accountNumber: number, phoneNumber: number, identifier: string, identifierType: string, lookupType: string): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.lookupCustomer ()'); } // getting the request options const options = this.httpOptions(); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue('storeId', storeId)); // constracting the query params const queryParams: Array = new Array(); if (accountNumber) { queryParams.push(new KeyValue('accountNumber', accountNumber)); } if (phoneNumber) { queryParams.push(new KeyValue('phoneNumber', phoneNumber)); } if (identifier) { queryParams.push(new KeyValue('identifier', identifier)); } if (identifierType) { queryParams.push(new KeyValue('identifierType', identifierType)); } if (lookupType) { queryParams.push(new KeyValue('lookupType', lookupType)); } // getting the final url const url = Utils.replaceAppendParams(restUrl.search.lookupCustomer, pathParams, queryParams); // service calling // return this._http.get ("assets/data/customer-lookup.json", options) return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.lookupCustomer ()'); } }),// for debug catchError(this.handleError)); } /** * Returns an Observable for the HTTP GET request for the JSON resource. * @return { IOrderList} The Observable for the HTTP request. */ lookupOrder( storeId: number, fullOrderId: string, firstName: string, lastName: string, phoneNumber: string, emailAddress: string, accountNumber: number, createdDateFrom: string, createdDateTo: string, status: string, refType: string, channel: string, logonId: string, dealerCode: string, webOrderId: string, sim: string, imei: string, ssn: string, retailStoreId: string): Observable { // setting flag for order more options or not // getting the request options const options = this.httpOptions(); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue('storeId', storeId)); // constracting the query params const queryParams: Array = new Array(); if (fullOrderId) { queryParams.push(new KeyValue('fullOrderId', fullOrderId)); } if (firstName) { queryParams.push(new KeyValue('firstName', firstName)); } if (lastName) { queryParams.push(new KeyValue('lastName', lastName)); } if (phoneNumber) { queryParams.push(new KeyValue('phoneNumber', phoneNumber)); } if (emailAddress) { queryParams.push(new KeyValue('emailAddress', emailAddress)); } if (accountNumber) { queryParams.push(new KeyValue('accountNumber', accountNumber)); } if (createdDateFrom) { queryParams.push(new KeyValue('createdDateFrom', createdDateFrom)); } if (createdDateTo) { queryParams.push(new KeyValue('createdDateTo', createdDateTo)); } if (status && status !== 'null') { queryParams.push(new KeyValue('status', status)); }; if (refType && refType !== 'null') { queryParams.push(new KeyValue('refType', refType)); }; if (channel && channel !== 'null') { queryParams.push(new KeyValue('channel', channel)); }; if (logonId) { queryParams.push(new KeyValue('logonId', logonId)); } if (dealerCode) { queryParams.push(new KeyValue('dealerCode', dealerCode)); } if (webOrderId) { queryParams.push(new KeyValue('webOrderId', webOrderId)); } if (sim) { queryParams.push(new KeyValue('sim', sim)); } if (imei) { queryParams.push(new KeyValue('imei', imei)); } if (ssn) { queryParams.push(new KeyValue('ssn', ssn)); } if (retailStoreId) { queryParams.push(new KeyValue('retailStoreId', retailStoreId)); } if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.lookupOrder ()'); } // getting the final url const url = Utils.replaceAppendParams(restUrl.search.lookupOrder, pathParams, queryParams); // service calling // return this._http.get ('assets/data/order-lookup.json').pipe( return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.lookupOrder ()'); } }),// for debug catchError(this.handleError)); } // Gets the order notes for a particular order Id. getOrderNotes(storeId: number, orderId: number): any { // getting the request options const options = this.httpOptions(); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue('storeId', storeId)); pathParams.push(new KeyValue('orderId', orderId)); // constracting the query params const queryParams: Array = new Array(); // getting the final url const url = Utils.replaceAppendParams(restUrl.order.getNotes, pathParams, queryParams); // service calling if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.getOrderNotes ()'); } return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.getOrderNotes ()'); } }),// for debug catchError(this.handleError)); } // Gets the order notes for a particular order Id. searchMemoNotes(storeId: number, orderId: number, accountNumber: number, orderCreateDate: any, refType: any): any { const headers = new Headers(); headers.append('dealercode', '0000000'); const cst = { headers: headers }; let options = this.httpOptions(); options = Object.assign(options, cst); // getting the request options // if (cart && cart.dealerCode) { // headers.append('dealercode', (cart.dealerCode.length === 8) ? (cart.dealerCode.substr(1)) : cart.dealerCode); // } else { // } // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue('storeId', storeId)); // constracting the query params const queryParams: Array = new Array(); if (refType === 'return') { queryParams.push(new KeyValue('memoCode', 'HOR')); queryParams.push(new KeyValue('memoSource', 'R')); } else { queryParams.push(new KeyValue('memoCode', 'CRDR')); queryParams.push(new KeyValue('memoSource', 'R')); } queryParams.push(new KeyValue('orderId', orderId)); queryParams.push(new KeyValue('accountNumber', accountNumber)); queryParams.push(new KeyValue('createDate', orderCreateDate)); // getting the final url const url = Utils.replaceAppendParams(restUrl.customer.searchMemo, pathParams, queryParams); // service calling if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.getOrderNotes ()'); } return this._http.get(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.getOrderNotes ()'); } }),// for debug catchError(this.handleError)); } // Creates an order note for a OrderId. createOrderNotes(storeId: number, orderId: number, requestParams: any): any { // getting the request options const options = this.httpOptions(); // constracting the path params const pathParams: Array = new Array(); pathParams.push(new KeyValue('storeId', storeId)); pathParams.push(new KeyValue('orderId', orderId)); // getting the final url requestParams.agentId = (requestParams.agentId) ? requestParams.agentId.toLowerCase() : requestParams.agentId; const url = Utils.replacePathParams(restUrl.order.createNotes, pathParams); if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.createOrderNotes ()'); } // service calling return this._http.post(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.createOrderNotes ()'); } }), // 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. */ cancelOrder(storeId: number, orderId: number): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-CustomerService.cancelOrder ()'); } // 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.order.cancelOrder, pathParams); // service calling return this._http.delete(url, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-CustomerService.cancelOrder ()'); } }),// 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. */ releaseOrder(storeId: number, orderId: number, requestParams: any): Observable { if (ServiceConstants.LOGGING) { console.log('[start]-lookupService.releaseOrder ()'); } // 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.order.releaseOrder, pathParams); // service calling return this._http.put(url, requestParams, options).pipe( map((res: any) => res), tap(data => { if (ServiceConstants.LOGGING) { console.log('[end]-lookupService.releaseOrder ()'); } }),// for debug catchError(this.handleError)); } }