Skip to content

Commit

Permalink
Add 'onr' param
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperengstrom committed Aug 6, 2024
1 parent 73ce53d commit 3bc4713
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 11 additions & 1 deletion lxl-web/src/lib/utils/holdings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export function getBibIdsByInstanceId(mainEntity, record) {
const bibId = instanceOfItem.meta?.controlNumber || record?.controlNumber;
const type = instanceOfItem['@type'];
const holders = instanceOfItem['@reverse']?.itemOf?.map((i) => i?.heldBy?.sigel);

// add Legacy Libris III system number for ONR param
let onr = null;
record?.identifiedBy?.forEach((el: { '@type': string; value: string }) => {
if (el['@type'] === 'LibrisIIINumber') {
onr = el.value;
}
});

if (!id) {
return acc;
}
Expand All @@ -68,7 +77,8 @@ export function getBibIdsByInstanceId(mainEntity, record) {
[id]: {
bibId,
'@type': type,
holders
holders,
onr
}
};
}, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
// if holdingUrl is an instance fnurgel, add its mapped bibId into arr,
// else add all ids of current type with holdings for current sigel
$: bibIds = $page.data.bibIdsByInstanceId[holdingUrl]
? [$page.data.bibIdsByInstanceId[holdingUrl].bibId]
? [$page.data.bibIdsByInstanceId[holdingUrl]]
: Object.keys($page.data.bibIdsByInstanceId)
.filter((i) => $page.data.bibIdsByInstanceId[i]['@type'] === holdingUrl)
.filter((i) => $page.data.bibIdsByInstanceId[i].holders.includes(sigel))
.map((i) => $page.data.bibIdsByInstanceId[i].bibId);
.map((i) => $page.data.bibIdsByInstanceId[i]);
async function fetchHoldingStatus(ids: string[]) {
async function fetchHoldingStatus(ids: Record<string, string>[]) {
const promises = ids.map((id) => {
if (id) {
return fetch(`/api/holdingstatus?sigel=${sigel}&bib_id=${id}`);
const searchParams = new URLSearchParams();
searchParams.set('bib_id', id.bibId);
searchParams.set('sigel', sigel);
if (id.onr) {
searchParams.set('onr', id.onr);
}
return fetch(`/api/holdingstatus?${searchParams.toString()}`);
}
});
Expand Down Expand Up @@ -63,6 +69,7 @@
case 'ej utlånad':
case 'available':
return 'available';
case 'ej tillgänglig':
case 'utlånad':
case 'on loan':
case 'not available':
Expand Down

0 comments on commit 3bc4713

Please sign in to comment.