rename the product group table to either product category or menu category move the group_type field from productgroup to products and name it sales category eg. Food, beverage, etc. also, set the tax for sales category and not individual product Added the printers permission to end of permissions and only for owner, set them right
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
|
import {ErrorLoggerService} from '../core/error-logger.service';
|
|
import {catchError} from 'rxjs/operators';
|
|
import {Observable} from 'rxjs/internal/Observable';
|
|
import {Printer} from './printer';
|
|
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
|
};
|
|
const url = '/v1/printers';
|
|
const serviceName = 'PrinterService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class PrinterService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
|
}
|
|
|
|
get(id: string): Observable<Printer> {
|
|
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
|
return <Observable<Printer>>this.http.get<Printer>(getUrl)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
|
);
|
|
}
|
|
|
|
list(): Observable<Printer[]> {
|
|
const options = {params: new HttpParams().set('l', '')};
|
|
return <Observable<Printer[]>>this.http.get<Printer[]>(url, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'list'))
|
|
);
|
|
}
|
|
|
|
save(printer: Printer): Observable<Printer> {
|
|
return <Observable<Printer>>this.http.post<Printer>(`${url}/new`, printer, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'save'))
|
|
);
|
|
}
|
|
|
|
update(printer: Printer): Observable<Printer> {
|
|
return <Observable<Printer>>this.http.put<Printer>(`${url}/${printer.id}`, printer, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'update'))
|
|
);
|
|
}
|
|
|
|
saveOrUpdate(printer: Printer): Observable<Printer> {
|
|
if (!printer.id) {
|
|
return this.save(printer);
|
|
} else {
|
|
return this.update(printer);
|
|
}
|
|
}
|
|
|
|
delete(id: string): Observable<Printer> {
|
|
return <Observable<Printer>>this.http.delete<Printer>(`${url}/${id}`, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'delete'))
|
|
);
|
|
}
|
|
}
|