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';
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,
}
},
{}
- ).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();
resolve();
},
error => {
- console.debug(error);
reject();
- }
+ },
);
});
}
} 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']);
+ }
+ ),
]);
}
}