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 { constructor(private ser: VoucherService) {} resolve(route: ActivatedRouteSnapshot): Observable { 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'); } }