1 import {Injectable} from '@angular/core';
2 import {IdlObject} from '@eg/core/idl.service';
3 import {NetService} from '@eg/core/net.service';
4 import {EventService} from '@eg/core/event.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {Observable} from 'rxjs';
11 export class PatronService {
13 private net: NetService,
14 private evt: EventService,
15 private pcrud: PcrudService,
16 private auth: AuthService
19 bcSearch(barcode: string): Observable<any> {
20 return this.net.request(
22 'open-ils.actor.get_barcodes',
23 this.auth.token(), this.auth.user().ws_ou(),
24 'actor', barcode.trim());
27 getByBarcode(barcode: string, pcrudOps?: any): Promise<IdlObject> {
28 return this.bcSearch(barcode).toPromise()
31 // Use the first successful barcode response.
32 // TODO: What happens when there are multiple responses?
33 // Use for-loop for early exit since we have async
34 // action within the loop.
35 for (let i = 0; i < barcodes.length; i++) {
36 const bc = barcodes[i];
37 if (!this.evt.parse(bc)) {
38 return this.getById(bc.id);
46 getById(id: number, pcrudOps?: any): Promise<IdlObject> {
47 return this.pcrud.retrieve('au', id, pcrudOps).toPromise();