Init webapp
This commit is contained in:
@@ -1,22 +1,34 @@
|
||||
import { MeterData } from './../models/Meterdata';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Meter } from 'src/app/models/Meter';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Injectable } from "@angular/core";
|
||||
import {
|
||||
HttpClient,
|
||||
HttpErrorResponse,
|
||||
HttpHeaders,
|
||||
} from "@angular/common/http";
|
||||
import { Observable, throwError } from "rxjs";
|
||||
import { catchError } from "rxjs/operators";
|
||||
import { environment } from "src/environments/environment";
|
||||
import { MeterData } from "../dataModels/Meterdata";
|
||||
import { Meter } from "../dataModels/Meter";
|
||||
import { LoginService } from "../auth/login.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
providedIn: "root",
|
||||
})
|
||||
export class DatabaseService {
|
||||
private baseUrl = environment.hostUrl + '/v1';
|
||||
private baseUrl = environment.apiBaseUrl;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
constructor(private http: HttpClient, private userService: LoginService) {}
|
||||
|
||||
getMeterData(): Observable<MeterData[]> {
|
||||
const url = `${this.baseUrl}/meter-data`;
|
||||
return this.http.get<MeterData[]>(url).pipe(catchError(this.handleError));
|
||||
let jwtToken: String = this.userService.getUserSecurityToken(),
|
||||
headers: HttpHeaders = new HttpHeaders({
|
||||
authorization: "bearer " + jwtToken,
|
||||
}),
|
||||
options = { headers: headers };
|
||||
return this.http
|
||||
.get<MeterData[]>(url, options)
|
||||
.pipe(catchError(this.handleError));
|
||||
}
|
||||
|
||||
getMeterDataByType(usageType: string): Observable<MeterData[]> {
|
||||
@@ -41,7 +53,7 @@ export class DatabaseService {
|
||||
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
// A client-side or network error occurred. Handle it accordingly.
|
||||
console.error('An error occurred:', error.error.message);
|
||||
console.error("An error occurred:", error.error.message);
|
||||
} else {
|
||||
// The backend returned an unsuccessful response code.
|
||||
// The response body may contain clues as to what went wrong.
|
||||
|
||||
Reference in New Issue
Block a user