add dashboard service

This commit is contained in:
Tim Herbst 2020-12-22 07:55:20 +01:00
parent 7c1612f8da
commit 281fb3ae40
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { DashboardService } from './dashboard.service';
describe('DashboardService', () => {
let service: DashboardService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DashboardService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import {Injectable} from '@angular/core';
import {IDashboardCommonBikePoint} from './domain/dashboard-common-bike-point';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class DashboardService {
public station: IDashboardCommonBikePoint;
constructor(private client: HttpClient) {
}
setBikeStation(id: string): void {
this.initialDashboardStationFetch(id).then((data) => {
this.station = data;
console.log(this.station);
}).catch((error) => {
console.log('something went wrong: ' + JSON.stringify(error));
});
}
private async initialDashboardStationFetch(id: string): Promise<any> {
return await this.client.get(environment.apiUrl + 'latest/dashboard/' + id + '/').toPromise();
}
}