Skip to content

Commit

Permalink
Merge pull request #427 from NYPL/NOREF-fix-missing-recordtype-label
Browse files Browse the repository at this point in the history
Fix issue when recordType not recognized in NYPL-Core
  • Loading branch information
nonword authored Dec 16, 2024
2 parents e82c7cc + 144682b commit 9805396
Show file tree
Hide file tree
Showing 3 changed files with 1,618 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ class ResourceSerializer extends JsonLdItemSerializer {
}

ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
const prefLabel = recordTypes[recordTypeId]?.label
if (!prefLabel) return null
return {
'@id': recordTypeId,
prefLabel: recordTypes[recordTypeId].label
prefLabel
}
}

Expand Down Expand Up @@ -501,12 +503,16 @@ class AggregationSerializer extends JsonLdItemSerializer {
} else if (field === 'recordType') {
// Build recordType agg labels from nypl-core:
v.label = recordTypes[v.value]?.label
// Unknown recordType? Remove it:
if (!v.label) return null
} else {
v.label = v.value
}

return v
})
// Remove null aggregations (removed because found to be invalid)
.filter((agg) => agg)
} catch (e) { console.error(e) }

// Now that we've formatted buckets (into `values` prop), delete `buckets`
Expand Down
Loading

0 comments on commit 9805396

Please sign in to comment.