LP#1787274 Prevent multiple active copy checkins
authorBill Erickson <berickxx@gmail.com>
Mon, 17 Sep 2018 22:16:28 +0000 (18:16 -0400)
committerKathy Lussier <klussier@masslnc.org>
Tue, 18 Sep 2018 18:44:54 +0000 (14:44 -0400)
In the staff client checkin service, track which copies are currently
in-flight to the checkin API call and prevent additional checkin API
calls for any copy that is currently in flight.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/circ/services/circ.js

index 25e4fc1..724ae7f 100644 (file)
@@ -19,7 +19,8 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
             hold_shelf_slip : false,
             hold_transit_slip : false,
             transit_slip : false
-        }
+        },
+        in_flight_checkins: {}
     };
 
     egCore.startup.go().finally(function() {
@@ -266,10 +267,20 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
                 var method = 'open-ils.circ.checkin';
                 if (options.override) method += '.override';
 
+                // Multiple checkin API calls should never be active
+                // for a single barcode.
+                if (service.in_flight_checkins[barcode]) {
+                    console.error('Barcode ' + barcode 
+                        + ' is already in flight for checkin, skipping');
+                    return $q.reject();
+                }
+                service.in_flight_checkins[barcode] = true;
+
                 return egCore.net.request(
                     'open-ils.circ', method, egCore.auth.token(), params
 
                 ).then(function(evt) {
+                    delete service.in_flight_checkins[barcode];
 
                     if (!angular.isArray(evt)) evt = [evt];
                     return service.flesh_response_data(
@@ -280,7 +291,7 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
                     .then(function(final_resp) {
                         return service.munge_resp_data(final_resp,'checkin',method)
                     })
-                });
+                }, function() {delete service.in_flight_checkins[barcode]});
             });
         });
     }