loaded = false;
+ accountExpired = false;
+ accountExpiresSoon = false;
+
constructor(
private net: NetService,
private auth: AuthService,
.then(_ => this.loaded = true);
}
- getPatronStats(id: number): Promise<any> {
+ setExpires(): Promise<any> {
+ this.accountExpired = false;
+ this.accountExpiresSoon = false;
+
+ return this.patronService.testExpire(this.patron)
+ .then(value => {
+ if (value === 'expired') {
+ this.accountExpired = true;
+ } else if (value === 'soon') {
+ this.accountExpiresSoon = true;
+ }
+ });
+ }
+
+ getPatronStats(id: number): Promise<any> {
return this.net.request(
'open-ils.actor',
import {Injectable} from '@angular/core';
import {IdlObject} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
+import {OrgService} from '@eg/core/org.service';
import {EventService} from '@eg/core/event.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {AuthService} from '@eg/core/auth.service';
export class PatronService {
constructor(
private net: NetService,
+ private org: OrgService,
private evt: EventService,
private pcrud: PcrudService,
private auth: AuthService
if (!patron) { return ''; }
return patron['pref_' + part]() || patron[part]();
}
+
+
+ // Returns promise of 'expired', 'soon', or null depending on the
+ // expire date disposition of the provided patron.
+ testExpire(patron: IdlObject): Promise<'expired' | 'soon'> {
+
+ const expire = new Date(Date.parse(patron.expire_date()));
+ if (expire < new Date()) {
+ return Promise.resolve('expired');
+ }
+
+ return this.org.settings(['circ.patron_expires_soon_warning'])
+ .then(setting => {
+ const days = setting['circ.patron_expires_soon_warning'];
+
+ if (Number(days)) {
+ const preExpire = new Date();
+ preExpire.setDate(preExpire.getDate() + Number(days));
+ if (expire < preExpire) { return 'soon'; }
+ }
+
+ return null;
+ });
+ }
}