brewman/overlord/src/app/purchase-entries/purchase-entries.service.ts

29 lines
1004 B
TypeScript
Raw Normal View History

import { HttpClient } 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 { PurchaseEntries } from './purchase-entries';
const url = '/api/purchase-entries';
const serviceName = 'PurchaseEntriesService';
@Injectable({
providedIn: 'root',
})
export class PurchaseEntriesService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
2020-11-23 11:12:54 +00:00
list(startDate: string | null, finishDate: string | null): Observable<PurchaseEntries> {
const startDateWithSlash = startDate ? `/${startDate}` : '';
const finishDateWithSlash = finishDate ? `/${finishDate}` : '';
return <Observable<PurchaseEntries>>(
this.http
.get<PurchaseEntries>(`${url}${startDateWithSlash}${finishDateWithSlash}`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
}