Skip to content

Commit

Permalink
add format to discovery api response
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Feb 28, 2025
1 parent 79d435b commit 3132c8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/production.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=

NYPL_CORE_VERSION=v2.27
NYPL_CORE_VERSION=v2.28

LOG_LEVEL=info
FEATURES=on-site-edd
Expand Down
2 changes: 1 addition & 1 deletion config/qa.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=

NYPL_CORE_VERSION=v2.27
NYPL_CORE_VERSION=v2.28

LOG_LEVEL=debug
FEATURES=on-site-edd
Expand Down
14 changes: 10 additions & 4 deletions lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,16 @@ class ResourceSerializer extends JsonLdItemSerializer {
stmts.hasItemDates = this.body.numItemDatesParsed[0] / numItems >= parseFloat(process.env.BIB_HAS_DATES_THRESHOLD)
}
}
// this value was indexed but is not being used for anything.
if (this.body.recordTypeId) {
stmts.recordType = ResourceSerializer.getFormattedRecordType(this.body.recordTypeId)
stmts.recordType = ResourceSerializer.getFormattedMaterialLikeType(this.body.recordTypeId, 'recordTypes')
delete stmts.recordTypeId
}
// This is the value that we use to determine format for filtering
if (this.body.formatId) {
stmts.format = ResourceSerializer.getFormattedMaterialLikeType(this.body.recordTypeId, 'formats')
delete stmts.formatId
}

// DFE depends on this being set to an empty array when null:
stmts.electronicResources = stmts.electronicResources || []
Expand All @@ -285,11 +291,11 @@ class ResourceSerializer extends JsonLdItemSerializer {
}
}

ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
const prefLabel = nyplCore.recordTypes()[recordTypeId]?.label
ResourceSerializer.getFormattedMaterialLikeType = function (id, property) {
const prefLabel = nyplCore[property]()[id]?.label
if (!prefLabel) return null
return {
'@id': recordTypeId,
'@id': id,
prefLabel
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/load_nypl_core.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const _data = {}
const nyplCoreObjects = require('@nypl/nypl-core-objects')

const loadNyplCoreData = () => {
const vocabularies = {
sierraLocations: 'by-sierra-location',
recordTypes: 'by-record-types',
recapCustomerCodes: 'by-recap-customer-code',
m2CustomerCodes: 'by-m2-customer-code',
patronTypes: 'by-patron-type'
patronTypes: 'by-patron-type',
formats: 'by-formats'
}
return Promise.all(Object.keys(vocabularies).map(async (vocab) => {
const nyplCoreValues = await nyplCoreObjects(vocabularies[vocab])
Expand All @@ -17,6 +17,7 @@ const loadNyplCoreData = () => {

module.exports = {
loadNyplCoreData,
formats: () => _data.formats || {},
patronTypes: () => _data.patronTypes || {},
sierraLocations: () => _data.sierraLocations || {},
recapCustomerCodes: () => _data.recapCustomerCodes || {},
Expand Down

0 comments on commit 3132c8f

Please sign in to comment.