Files
brewman/overlord/src/app/daybook/daybook.service.ts
T
2023-07-23 09:01:18 +05:30

30 lines
935 B
TypeScript

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 { Daybook } from './daybook';
const url = '/api/daybook';
const serviceName = 'DaybookService';
@Injectable({
providedIn: 'root',
})
export class DaybookService {
constructor(
private http: HttpClient,
private log: ErrorLoggerService,
) {}
list(startDate: string | null, finishDate: string | null): Observable<Daybook> {
const startDateWithSlash = startDate ? `/${startDate}` : '';
const finishDateWithSlash = finishDate ? `/${finishDate}` : '';
return this.http
.get<Daybook>(`${url}${startDateWithSlash}${finishDateWithSlash}`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Daybook>;
}
}