import { Injectable } from '@angular/core'; import { IpServiceService } from './ipservice'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { environment as env } from '../environments/environment'; @Injectable() export class AuditbotLibService { constructor(private ip: IpServiceService, private httpClient: HttpClient) { } ipAddress: string; private REST_API_SERVER = env.apiUrl; authTokenKey: string; Initialize(authTokenKey: string) { this.ipAddress = sessionStorage.getItem('IPADDRESS'); this.authTokenKey = authTokenKey; if (!this.ipAddress) { this.ip.getIPAddress().subscribe((res: any) => { sessionStorage.setItem('IPADDRESS', res.ip); }); } } public getAuditRecords(hashKey: string, currentPage: number, totalRecords: number): Observable { var authToken: string = null; authToken = localStorage.getItem(this.authTokenKey); if (!authToken) { authToken = sessionStorage.getItem(this.authTokenKey); } if (authToken && !authToken.startsWith('Bearer')) { authToken = 'Bearer ' + authToken; } let headers = new HttpHeaders().set('Content-Type', 'application/json') .set('Authorization', authToken); return this.httpClient.get(this.REST_API_SERVER + '?hashkey=' + hashKey + '¤tPage=' + currentPage + '&noOfRecords=' + totalRecords , { headers: headers }); } }