@@ -7,50 +7,73 @@ class RequestabilityResolver {
77 static fixItemRequestability ( elasticSearchResponse ) {
88 elasticSearchResponse . hits . hits
99 . forEach ( ( hit ) => {
10- const parentBibHasFindingAid = ! ! hit . _source . supplementaryContent ?. find ( ( el ) => el . label . toLowerCase ( ) === 'finding aid' )
1110 hit . _source . items = hit . _source . items . map ( ( item ) => {
1211 if ( item . electronicLocator ) return item
13- let deliveryInfo
1412 const itemIsInRecap = isInRecap ( item )
15- let physRequestableCriteria
16- const hasRecapCustomerCode = item . recapCustomerCode ?. [ 0 ]
17- if ( itemIsInRecap ) {
18- // recap items missing codes should default to true for phys and edd
19- // requestable, unless it has a non-requestable holding location
20- deliveryInfo = DeliveryLocationsResolver . getRecapDeliveryInfo ( item )
21- physRequestableCriteria = hasRecapCustomerCode
22- ? `${ ( deliveryInfo . deliveryLocation ?. length ) || 0 } delivery locations.`
23- : 'Missing customer code'
24- } else if ( ! itemIsInRecap ) {
25- deliveryInfo = DeliveryLocationsResolver . getOnsiteDeliveryInfo ( item )
26- physRequestableCriteria = `${ ( deliveryInfo . deliveryLocation ?. length ) || 0 } delivery locations.`
27- }
28- item . specRequestable = this . buildSpecRequestable ( item , parentBibHasFindingAid )
29- item . physRequestable = ! ! deliveryInfo . deliveryLocation ?. length
13+ const deliveryInfo = itemIsInRecap
14+ ? DeliveryLocationsResolver . getRecapDeliveryInfo ( item )
15+ : DeliveryLocationsResolver . getOnsiteDeliveryInfo ( item )
16+ const numDeliveryLocations = deliveryInfo . deliveryLocation ?. length
17+ item . specRequestable = this . buildSpecRequestable ( item )
18+ item . physRequestable = this . buildPhysRequestable ( item , numDeliveryLocations )
3019 item . eddRequestable = ! ! deliveryInfo . eddRequestable && ! item . specRequestable
31- // items without barcodes should not be requestable
32- const hasBarcode = ( item . identifier || [ ] ) . some ( ( identifier ) => / ^ ( u r n | b f ) : [ b B ] a r c o d e : \w + / . test ( identifier ) )
33- if ( isItemNyplOwned ( item ) && ! hasBarcode ) {
34- physRequestableCriteria = 'NYPL item missing barcode'
35- item . physRequestable = false
36- }
37- if ( item . specRequestable && item . physRequestable ) {
38- item . physRequestable = false
39- physRequestableCriteria = 'specRequestable overrides physRequestable location'
40- }
41- logger . debug ( `item ${ item . uri } : ` , { physRequestable : item . physRequestable , physRequestableCriteria } )
4220 item . requestable = [ item . eddRequestable || item . physRequestable || item . specRequestable ]
4321 return item
4422 } )
4523 } )
4624 return elasticSearchResponse
4725 }
4826
49- static buildSpecRequestable ( item , parentBibHasFindingAid ) {
27+ static buildPhysRequestable ( item , numDeliveryLocations ) {
28+ let physRequestableCriteria
29+ let physRequestable
30+ const hasRecapCustomerCode = item . recapCustomerCode ?. [ 0 ]
31+ const itemIsInRecapMissingRecapCustomerCode = isInRecap ( item ) && ! hasRecapCustomerCode
32+ // items without barcodes should not be requestable
33+ const hasBarcode = ( item . identifier || [ ] ) . some ( ( identifier ) => / ^ ( u r n | b f ) : [ b B ] a r c o d e : \w + / . test ( identifier ) )
34+ if ( isItemNyplOwned ( item ) && ! hasBarcode ) {
35+ physRequestable = false
36+ physRequestableCriteria = 'NYPL item missing barcode'
37+ this . logPhysRequestableInfo ( physRequestable , physRequestableCriteria , item . uri )
38+ return physRequestable
39+ }
40+ if ( isItemNyplOwned ( item ) && ! DeliveryLocationsResolver . requestableBasedOnHoldingLocation ( item ) ) {
41+ physRequestableCriteria = 'Unrequestable holding location'
42+ physRequestable = false
43+ this . logPhysRequestableInfo ( physRequestable , physRequestableCriteria , item . uri )
44+ return physRequestable
45+ }
46+ if ( itemIsInRecapMissingRecapCustomerCode ) {
47+ // recap items missing codes should default to true for phys and edd
48+ // requestable, if it has a requestable holding location.
49+ physRequestable = true
50+ physRequestableCriteria = 'Missing customer code'
51+ this . logPhysRequestableInfo ( physRequestable , physRequestableCriteria , item . uri )
52+ return physRequestable
53+ }
54+ if ( numDeliveryLocations === 0 ) {
55+ physRequestableCriteria = 'No delivery locations.'
56+ physRequestable = false
57+ this . logPhysRequestableInfo ( physRequestable , physRequestableCriteria , item . uri )
58+ return physRequestable
59+ }
60+ if ( numDeliveryLocations > 0 ) {
61+ physRequestableCriteria = `${ numDeliveryLocations } delivery locations.`
62+ physRequestable = true
63+ this . logPhysRequestableInfo ( physRequestable , physRequestableCriteria , item . uri )
64+ return physRequestable
65+ }
66+ }
67+
68+ static logPhysRequestableInfo ( physRequestable , criteria , uri ) {
69+ logger . debug ( `item ${ uri } : ${ { physRequestable, criteria } } ` )
70+ }
71+
72+ static buildSpecRequestable ( item ) {
5073 const holdingLocation = DeliveryLocationsResolver . extractLocationCode ( item )
5174 const nyplCoreLocation = DeliveryLocationsResolver . nyplCoreLocation ( holdingLocation )
5275 const isSpecialCollectionsOnlyAccessType = ! ! ( nyplCoreLocation ?. collectionAccessType === 'special' )
53- return ! ! item . aeonUrl || parentBibHasFindingAid || isSpecialCollectionsOnlyAccessType
76+ return ! ! item . aeonUrl || isSpecialCollectionsOnlyAccessType
5477 }
5578}
5679
0 commit comments