import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ResourcesService } from './resources.service';
import { apiTemp } from '../../environments/environment.prod';

@Injectable({
  providedIn: 'root'
})
export class HttpRequestService {

  private _url:string;

  constructor(private _http: HttpClient, private _resourcesService: ResourcesService) {
    this._url = `${apiTemp}`;
  }

  public getQuery(query: string) {    
    const URL = `${this._url}${query}`;
    return this._http.get(URL, {
      headers: new HttpHeaders({ Authorization: `Bearer ${ this._resourcesService.getToken() }` }),
    });
  }

  public postQuery(query: string, body: any) {
    const URL = `${this._url}${query}`;
    return this._http.post(URL, body, {
      headers: new HttpHeaders({ Authorization: `Bearer ${ this._resourcesService.getToken() }` }),
    });
  }
}
