23 lines
813 B
TypeScript
23 lines
813 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 { Batch } from './batch';
|
|
import { ErrorLoggerService } from './error-logger.service';
|
|
|
|
const url = '/api/batch';
|
|
const serviceName = 'BatchService';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class BatchService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
autocomplete(date: string, term: string): Observable<Batch[]> {
|
|
const options = { params: new HttpParams().set('q', term).set('d', date) };
|
|
return this.http
|
|
.get<Batch[]>(url, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<Batch[]>;
|
|
}
|
|
}
|