-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestability_resolver.js
More file actions
80 lines (75 loc) · 3.6 KB
/
requestability_resolver.js
File metadata and controls
80 lines (75 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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) => {
hit._source.items = hit._source.items.map((item) => {
if (item.electronicLocator) return item
const itemIsInRecap = isInRecap(item)
const deliveryInfo = itemIsInRecap
? DeliveryLocationsResolver.getRecapDeliveryInfo(item)
: DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
const numDeliveryLocations = deliveryInfo.deliveryLocation?.length
item.specRequestable = this.buildSpecRequestable(item)
item.physRequestable = this.buildPhysRequestable(item, numDeliveryLocations)
item.eddRequestable = !!deliveryInfo.eddRequestable && !item.specRequestable
item.requestable = [item.eddRequestable || item.physRequestable || item.specRequestable]
return item
})
})
return elasticSearchResponse
}
static buildPhysRequestable (item, numDeliveryLocations) {
let physRequestableCriteria
let physRequestable
const hasRecapCustomerCode = item.recapCustomerCode?.[0]
const itemIsInRecapMissingRecapCustomerCode = isInRecap(item) && !hasRecapCustomerCode
// items without barcodes should not be requestable
const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier))
if (isItemNyplOwned(item) && !hasBarcode) {
physRequestable = false
physRequestableCriteria = 'NYPL item missing barcode'
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
return physRequestable
}
if (isItemNyplOwned(item) && !DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
physRequestableCriteria = 'Unrequestable holding location'
physRequestable = false
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
return physRequestable
}
if (itemIsInRecapMissingRecapCustomerCode) {
// recap items missing codes should default to true for phys and edd
// requestable, if it has a requestable holding location.
physRequestable = true
physRequestableCriteria = 'Missing customer code'
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
return physRequestable
}
if (numDeliveryLocations === 0) {
physRequestableCriteria = 'No delivery locations.'
physRequestable = false
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
return physRequestable
}
if (numDeliveryLocations > 0) {
physRequestableCriteria = `${numDeliveryLocations} delivery locations.`
physRequestable = true
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
return physRequestable
}
}
static logPhysRequestableInfo (physRequestable, criteria, uri) {
logger.debug(`item ${uri}: ${{ physRequestable, criteria }}`)
}
static buildSpecRequestable (item) {
const holdingLocation = DeliveryLocationsResolver.extractLocationCode(item)
const nyplCoreLocation = DeliveryLocationsResolver.nyplCoreLocation(holdingLocation)
const isSpecialCollectionsOnlyAccessType = !!(nyplCoreLocation?.collectionAccessType === 'special')
return !!item.aeonUrl || isSpecialCollectionsOnlyAccessType
}
}
module.exports = RequestabilityResolver