@rero/rero-ils-ui
Version:
User interface for RERO integrated library system (RERO ILS).
2 lines (1 loc) • 2.96 kB
JavaScript
import{d as f}from"./chunk-5357H5SV.js";import{a as p,b as _}from"./chunk-PDQWUDUO.js";import{Ua as g,Wa as d,a as u}from"./chunk-MTJX6JRK.js";import{i as m}from"./chunk-4MYHQLZQ.js";import{da as h,ia as c,v as s}from"./chunk-3WD6XLXL.js";var E=(function(r){return r.OPEN="open",r.CLOSED="closed",r})(E||{}),N=(function(r){return r.FEE="fee",r.PAYMENT="payment",r.DISPUTE="dispute",r.CANCEL="cancel",r})(N||{}),I=class{constructor(n){this.status=E.OPEN,this.total_amount=0,this.events=[],this.note=null,this.document=null,this.library=null,this.loan=null,this.patron=null,Object.assign(this,n)}get_events(){return this.events.sort((n,e)=>{let t=u.fromISO(n.creation_date);return u.fromISO(e.creation_date).diff(t)})}},S=class{constructor(n){this.creation_date=null,this.amount=0,Object.assign(this,n)}};var P=(()=>{class r{constructor(){this.httpClient=c(m),this.apiService=c(g),this.recordService=c(d)}getPatron(e){return this.recordService.getRecords("patrons",{query:`patron.barcode:${e}`,page:1,itemsPerPage:1}).pipe(s(t=>{switch(this.recordService.totalHits(t.hits.total)){case 0:return;case 1:return t.hits.hits[0].metadata;default:throw new Error("too much results")}}))}getPatronByPid(e){return this.recordService.getRecord("patrons",e).pipe(s(t=>t.metadata))}getItems(e,t){t===void 0&&(t="-transaction_date");let a=`${this.apiService.getEndpointByType("item")}/loans/${e}?sort=${t}`;return this.httpClient.get(a).pipe(s(o=>o.hits),s(o=>this.recordService.totalHits(o.total)===0?[]:o.hits),s(o=>o.map(l=>this._buildItem(l))))}getItem(e){return this.httpClient.get(`/api/item/barcode/${e}`).pipe(s(t=>this._buildItem(t.metadata)))}_buildItem(e){let t=new f(e.item);return e.loan&&t.setLoan(e.loan),t}getItemsRequested(e){return this.getLoans(`patron_pid:${e} AND (state:PENDING OR state:ITEM_IN_TRANSIT_FOR_PICKUP)`)}getItemsPickup(e){return this.getLoans(`patron_pid:${e} AND state:ITEM_AT_DESK`)}getHistory(e,t,i){t=t||Math.round(6*365/12),i=i||0;let o=[p.CANCELLED,p.ITEM_IN_TRANSIT_TO_HOUSE,p.ITEM_RETURNED].map(v=>`state:${v}`).join(" OR "),l=`patron_pid:${e} AND (${o}) end_date:[now-${t}d/d TO now-${i}d/d]`;return this.getLoans(l,"duedate")}getCirculationInformations(e){let t=[this.apiService.getEndpointByType("patrons"),e,"circulation_informations"].join("/");return this.httpClient.get(t)}getOverduePreview(e){let t=[this.apiService.getEndpointByType("patrons"),e,"overdues","preview"].join("/");return this.httpClient.get(t).pipe(s(i=>i.map(a=>({fees:a.fees,loan:new _(a.loan)}))))}getLoans(e,t){return this.recordService.getRecords("loans",{query:e,page:1,itemsPerPage:d.MAX_REST_RESULTS_SIZE,aggregationsFilters:[],preFilters:{},headers:{Accept:"application/rero+json"},sort:t}).pipe(s(i=>i.hits),s(i=>+this.recordService.totalHits(i.total)==0?[]:i.hits))}static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275prov=h({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})();export{E as a,N as b,I as c,S as d,P as e};