download household on same address

This commit is contained in:
2021-10-01 14:34:27 +02:00
parent c179649c56
commit 58a8949cac
4 changed files with 64 additions and 62 deletions

View File

@@ -1,44 +1,8 @@
const _fetchHouseholdByAddressReference = (reference, page) => {
const perPage = 50;
const url = `/api/1.0/person/household/by-address-reference/${reference.id}.json?`
+ new URLSearchParams({item_per_page: perPage, page });
return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
}).then(response => {
if (response.ok()) { return response.json(); }
throw Error({m: response.statusText });
});
}
import { fetchResults } from 'ChillMainAssets/lib/api/download.js';
const fetchHouseholdByAddressReference = async (reference) => {
const url = `/api/1.0/person/household/by-address-reference/${reference.id}.json?`
+ new URLSearchParams({});
return _fetchHouseholdByAddressReference(reference, 1).then(data => {
let promises = [];
promises.push(Promise.resolve(data.results));
if (data.pagination.more) {
let count = data.count;
let per_page = data.pagination.item_per_page;
let at_end = data.count
let page = 1;
while ((at_end + per_page) < count) {
page = page + 1;
at_end = at_end + per_page;
promises.push(_fetchHouseholdByAddressReference(reference, page).then(data => {
return Promise.resolve(data.results);
}));
}
}
return Promise.all(promises).then(results => {
return results.flat();
});
});
const url = `/api/1.0/person/household/by-address-reference/${reference.id}.json`
return fetchResults(url);
};
export {