31 lines
963 B
TypeScript
31 lines
963 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { Bill } from './bill';
|
|
import { VoucherService } from './voucher.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class BillResolver implements Resolve<Bill> {
|
|
constructor(private ser: VoucherService) {}
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<Bill> {
|
|
const tableId = route.queryParamMap.get('table');
|
|
const guestId = route.queryParamMap.get('guest');
|
|
const voucherId = route.queryParamMap.get('voucher');
|
|
const billId = route.queryParamMap.get('bill');
|
|
if (billId !== null) {
|
|
return this.ser.getFromBill(billId);
|
|
}
|
|
if (tableId !== null) {
|
|
return this.ser.getFromTable(tableId as string, voucherId, guestId);
|
|
}
|
|
if (voucherId !== null) {
|
|
return this.ser.getFromId(voucherId);
|
|
}
|
|
throw new Error('Unable to get bill');
|
|
}
|
|
}
|