No automatic signout

Voucher basic working
running tables shifted to cards from buttons, this gives us immense styling oportunities
This commit is contained in:
Amritanshu
2019-07-12 12:36:38 +05:30
parent 4513e8b263
commit bcad4cdae3
31 changed files with 1085 additions and 713 deletions

View File

@ -0,0 +1,70 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { ErrorLoggerService } from '../../core/error-logger.service';
import {Bill} from "./bill";
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/vouchers';
const serviceName = 'VoucherService';
@Injectable({providedIn: 'root'})
export class VoucherService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(id: string): Observable<Bill> {
return <Observable<Bill>>this.http.get<Bill>(`${url}/${id}`)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
}
getFromTable(tableId: string, voucherId: string, guestId: string): Observable<Bill> {
let params = new HttpParams();
if (tableId !== null) {
params = params.set('t', tableId);
}
if (voucherId !== null) {
params = params.set('v', voucherId);
}
if (guestId !== null) {
params = params.set('g', guestId);
}
return <Observable<Bill>>this.http.get<Bill>(`${url}/new`, {params: params})
.pipe(
catchError(this.log.handleError(
serviceName,
`getFromTable tableId=${tableId} voucherId=${voucherId} guestId=${guestId}`
))
);
}
save(voucher: Bill): Observable<Bill> {
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(voucher: Bill): Observable<Bill> {
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(voucher: Bill): Observable<Bill> {
if (!voucher.id) {
return this.save(voucher);
} else {
return this.update(voucher);
}
}
}