diff --git a/lib/requestability_resolver.js b/lib/requestability_resolver.js index 0b192d6..d4582fd 100644 --- a/lib/requestability_resolver.js +++ b/lib/requestability_resolver.js @@ -2,10 +2,12 @@ const DeliveryLocationsResolver = require('./delivery-locations-resolver') const { isItemNyplOwned } = require('./ownership_determination') const { isInRecap } = require('./util') const logger = require('./logger') + class RequestabilityResolver { static fixItemRequestability (elasticSearchResponse) { elasticSearchResponse.hits.hits .forEach((hit) => { + const parentBibHasFindingAid = !!hit._source.supplementaryContent?.find((el) => el.label === 'Finding aid') hit._source.items = hit._source.items.map((item) => { if (item.electronicLocator) return item let deliveryInfo @@ -28,7 +30,8 @@ class RequestabilityResolver { item.eddRequestable = !!deliveryInfo.eddRequestable item.physRequestable = !!(deliveryInfo.deliveryLocation && deliveryInfo.deliveryLocation.length) - item.specRequestable = !!item.aeonUrl + + item.specRequestable = this.buildSpecRequestable(item, parentBibHasFindingAid) // items without barcodes should not be requestable const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier)) if (isItemNyplOwned(item) && !hasBarcode) { @@ -42,6 +45,13 @@ class RequestabilityResolver { }) return elasticSearchResponse } + + static buildSpecRequestable (item, parentBibHasFindingAid) { + const holdingLocation = DeliveryLocationsResolver.extractLocationCode(item) + const nyplCoreLocation = DeliveryLocationsResolver.nyplCoreLocation(holdingLocation) + const isSpecialCollectionsOnlyAccessType = !!nyplCoreLocation?.collectionAccessType + return !!item.aeonUrl || parentBibHasFindingAid || isSpecialCollectionsOnlyAccessType + } } module.exports = RequestabilityResolver