luthor/otis/src/app/cause-list/cause-list.service.ts

32 lines
1022 B
TypeScript

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { CauseList } from './cause-list';
const url = '/api/cause-list';
const serviceName = 'CauseListService';
@Injectable({
providedIn: 'root',
})
export class CauseListService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
list(startDate: string | null, finishDate: string | null): Observable<CauseList> {
const options = { params: new HttpParams() };
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return this.http
.get<CauseList>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<CauseList>;
}
}