LP1840773 SCKO Angular
authorBill Erickson <berickxx@gmail.com>
Fri, 24 Jun 2022 14:19:49 +0000 (10:19 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 24 Jun 2022 14:19:49 +0000 (10:19 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/scko/banner.component.ts
Open-ILS/src/eg2/src/app/scko/fines.component.ts
Open-ILS/src/eg2/src/app/scko/scko.component.ts
Open-ILS/src/eg2/src/app/scko/scko.service.ts
Open-ILS/src/eg2/src/app/share/print/print.service.ts

index a5e3062..9a6a39c 100644 (file)
@@ -118,6 +118,7 @@ export class SckoBannerComponent implements OnInit {
 
     submitItemBarcode() {
         this.scko.resetPatronTimeout();
+        this.scko.checkout(this.itemBarcode);
     }
 }
 
index 373f415..f13bda7 100644 (file)
@@ -55,7 +55,7 @@ export class SckoFinesComponent implements OnInit {
                     },
                     select: {bre : ['id']}
                 }
-            ).pipe(tap(xact => this.xacts.push(xact)))
+            ).pipe(tap(xact => this.xacts.push(xact)));
         })).toPromise();
     }
 
@@ -78,7 +78,7 @@ export class SckoFinesComponent implements OnInit {
     }
 
     getDetails(xact: IdlObject): string {
-        if (xact.summary().xact_type() == 'circulation') {
+        if (xact.summary().xact_type() === 'circulation') {
             return this.getTitle(xact);
         } else {
             return xact.summary().last_billing_type();
index 4e21ebb..7da2bcf 100644 (file)
@@ -26,10 +26,8 @@ export class SckoComponent implements OnInit, AfterViewInit {
 
     ngOnInit() {
         this.net.authExpired$.subscribe(how => {
-            console.debug("SCKO auth expired with info", how);
-            this.scko.resetPatron();
-            this.auth.logout();
-            this.router.navigate(['/scko']);
+            console.debug('SCKO auth expired with info', how);
+            this.scko.logoutStaff();
         });
 
         this.scko.load();
index 2268edf..c3c8e28 100644 (file)
@@ -10,6 +10,12 @@ import {PatronService, PatronSummary, PatronStats} from '@eg/staff/share/patron/
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 import {PrintService} from '@eg/share/print/print.service';
 
+interface CheckoutStat {
+    override?: boolean;
+    redo?: boolean;
+    renew?: boolean;
+}
+
 @Injectable({providedIn: 'root'})
 export class SckoService {
 
@@ -38,6 +44,12 @@ export class SckoService {
         private patrons: PatronService,
     ) {}
 
+    logoutStaff() {
+        this.resetPatron();
+        this.auth.logout();
+        this.router.navigate(['/scko']);
+    }
+
     resetPatron() {
         this.patronSummary = null;
         this.sessionCheckouts = [];
@@ -195,15 +207,94 @@ export class SckoService {
     }
 
 
-    /*
-    logout(receiptType:
-    this.printer.print({
-    templateName: 'bills_current',
-    contextData: {xacts: rows},
-    printContext: 'default'
-    });
-    */
+    checkout(barcode: string, override?: boolean): Promise<any> {
+        this.resetPatronTimeout();
+
+        let method = 'open-ils.circ.checkout.full';
+        if (override) { method += '.override'; }
+
+        return this.net.request(
+            'open-ils.circ', method, this.auth.token(), {
+            patron_id: this.patronSummary.id,
+            copy_barcode: barcode
+        }).toPromise()
+
+        .then(result => {
+
+            console.debug('CO returned', result);
+
+            return this.handleCheckoutResult(result, barcode, 'checkout');
+
+        }).then(stat => {
+            console.debug('handleCheckoutResult returned', stat);
+
+            if (stat.override) {
+                return this.checkout(barcode, true);
+            } else if (stat.redo) {
+                return this.checkout(barcode);
+            } else if (stat.renew) {
+                return this.renew(barcode);
+            }
+        });
+
+        // return this.router.navigate(['/scko']);
+    }
+
+    renew(barcode: string, override?: boolean): Promise<any> {
+
+        let method = 'open-ils.circ.renew';
+        if (override) { method += '.override'; }
+
+        return this.net.request(
+            'open-ils.circ', method, this.auth.token(), {
+            patron_id: this.patronSummary.id,
+            copy_barcode: barcode
+        }).toPromise()
+
+        .then(result => {
+            console.debug('Renew returned', result);
 
+            return this.handleCheckoutResult(result, barcode, 'renew');
+
+        }).then(stat => {
+            console.debug('handleCheckoutResult returned', stat);
+
+            if (stat.override) {
+                return this.renew(barcode, true);
+            }
+        });
+    }
+
+
+    handleCheckoutResult(result: any,
+        barcode: string, action: string): Promise<CheckoutStat> {
+
+        if (Array.isArray(result)) {
+            result = result[0];
+        }
+
+        const evt: any = this.evt.parse(result) || {};
+        const payload = evt.payload || {};
+
+        if (evt.textcode === 'NO_SESSION') {
+            this.logoutStaff();
+            return;
+        }
+
+        if (evt.textcode === 'SUCCESS') {
+
+            if (action === 'checkout') {
+
+                return Promise.resolve({});
+
+            } else if (action === 'renew') {
+
+                return Promise.resolve({});
+            }
+        }
+
+        return Promise.resolve({}); // TODO
+    }
 }
 
 
index e2d7a97..de6682f 100644 (file)
@@ -101,7 +101,7 @@ export class PrintService {
                         reject({notFound: true});
                     } else {
                         console.error(
-                            "Print template generator returned status: " + this.status);
+                            'Print template generator returned status: ' + this.status);
                     }
                     reject({});
                 }