LH#27: navigate to search page if given direct link to provider that cannot be retrieved
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 1 Sep 2020 22:26:36 +0000 (18:26 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 1 Sep 2020 22:26:36 +0000 (18:26 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/resolver.service.ts

index cff63ae..2f3f823 100644 (file)
@@ -1,7 +1,7 @@
 import {Injectable} from '@angular/core';
 import {Observable, from} from 'rxjs';
 import {empty, throwError, Subject} from 'rxjs';
-import {map} from 'rxjs/operators';
+import {map, defaultIfEmpty} from 'rxjs/operators';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
@@ -69,6 +69,8 @@ export class ProviderRecordService {
     getProviderRecord(id: number): Observable<ProviderRecord> {
         console.debug('fetching provider ' + id);
         this.currentProviderId = id;
+        const emptyGuard = this.idl.create('acqpro');
+        emptyGuard.id('no_provider_fetched');
         return this.pcrud.search('acqpro', { id: id },
             {
                 flesh: 3,
@@ -85,7 +87,10 @@ export class ProviderRecordService {
                               }
             },
             {}
-        ).pipe(map(acqpro => {
+        ).pipe(defaultIfEmpty(emptyGuard), map(acqpro => {
+            if (acqpro.id() == 'no_provider_fetched') {
+                throw new Error('no provider to fetch');
+            }
             const provider = new ProviderRecord(acqpro);
             // make a copy of holding_tag for use by the holdings definitions tab
             acqpro['_holding_tag'] = acqpro.holding_tag();
@@ -168,9 +173,8 @@ export class ProviderRecordService {
                     resolve();
                 },
                 error => {
-                    console.debug(error);
                     reject();
-                }
+                },
             );
         });
     }
index 3020091..44e48f7 100644 (file)
@@ -30,7 +30,14 @@ export class ProviderResolver implements Resolve<Promise<any[]>> {
         } else {
             this.savedId = id;
             return Promise.all([
-                this.providerRecord.fetch(id),
+                this.providerRecord.fetch(id).then(
+                    ok => {
+                        console.debug(this.providerRecord.current());
+                    },
+                    err => {
+                        this.router.navigate(['/staff', 'acq', 'provider']);
+                    }
+                ),
             ]);
         }
     }