Show proper error messages on Save Bill / Save Kot

This commit is contained in:
Amritanshu Agrawal 2020-10-11 11:59:37 +05:30
parent 7baf79c3fa
commit 73f83f1aa7

View File

@ -59,10 +59,15 @@ export class SalesHomeComponent {
if (this.route.snapshot.queryParamMap.has('guest')) { if (this.route.snapshot.queryParamMap.has('guest')) {
guestBookId = this.route.snapshot.queryParamMap.get('guest'); guestBookId = this.route.snapshot.queryParamMap.get('guest');
} }
this.bs.printKot(guestBookId).subscribe(() => { this.bs.printKot(guestBookId).subscribe(
this.toaster.show('Success', ''); () => {
this.router.navigate(['/sales']); this.toaster.show('Success', '');
}); this.router.navigate(['/sales']);
},
(result) => {
this.toaster.show('Error', result);
},
);
} }
discountAllowed(): boolean { discountAllowed(): boolean {
@ -96,14 +101,7 @@ export class SalesHomeComponent {
} }
return this.dialog return this.dialog
.open(BillTypeComponent) .open(BillTypeComponent)
.afterClosed() .afterClosed();
.pipe(
tap((x) => {
if (!x) {
throwError('No Bill Type Chosen');
}
}),
);
} }
confirmTableDialog(table: Table): Observable<{ table: Table; confirmed: boolean }> { confirmTableDialog(table: Table): Observable<{ table: Table; confirmed: boolean }> {
@ -161,20 +159,21 @@ export class SalesHomeComponent {
} }
}), }),
switchMap(() => this.billTypeDialog()), switchMap(() => this.billTypeDialog()),
switchMap((x: boolean | PrintType) => { switchMap((x)=> {
if (x) { if (x) {
return this.bs.printBill(guestBookId, x as PrintType); return observableOf(x);
} }
return throwError(x); return throwError('No Bill Type Chosen')
}), }),
switchMap((x: PrintType) => this.bs.printBill(guestBookId, x as PrintType)),
) )
.subscribe( .subscribe(
() => { () => {
this.toaster.show('Success', ''); this.toaster.show('Success', '');
this.router.navigate(['/sales']); this.router.navigate(['/sales']);
}, },
() => { (result) => {
this.toaster.show('Error', 'No Bill Type Chosen'); this.toaster.show('Error', result);
}, },
); );
} }