mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
download household on same address
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user