Files
barker/bookie/src/app/section-printers/section-printer.service.ts
tanshu 6567f560ab Updated to angular 11
Now compiling with strict mode in typescript
Need to error checking now
2020-11-22 10:13:37 +05:30

54 lines
1.8 KiB
TypeScript

import { HttpClient, HttpHeaders } 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 { SectionPrinter } from '../core/section-printer';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/section-printers';
const serviceName = 'SectionPrinterService';
@Injectable({
providedIn: 'root',
})
export class SectionPrinterService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string | null): Observable<SectionPrinter[]> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<SectionPrinter[]>>(
this.http
.get<SectionPrinter[]>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
}
// item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
// const options = {params: new HttpParams().set('m', menuCategoryId)};
// return <Observable<SectionPrinterItem>>this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
// .pipe(
// catchError(this.log.handleError(serviceName, 'list'))
// );
// }
save(sectionId: string, list: SectionPrinter[]): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>(
this.http
.post<SectionPrinter[]>(`${url}/${sectionId}`, list, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
}
delete(id: string): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>(
this.http
.delete<SectionPrinter[]>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
}
}