@autofleet/network 1.4.7 → 1.4.8-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +23 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -161,4 +161,27 @@ module.exports = class Network {
|
|
|
161
161
|
|
|
162
162
|
return currentResult;
|
|
163
163
|
}
|
|
164
|
+
|
|
165
|
+
async getAllPagesFromQueryEndpoint(url, options = {}) {
|
|
166
|
+
let currentResult = [];
|
|
167
|
+
|
|
168
|
+
if(!options.perPage) {
|
|
169
|
+
throw new Error('Missing perPage option');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const perPage = options.perPage;
|
|
173
|
+
let lastResultSizeIsLessThanPerPage = false;
|
|
174
|
+
let page = 0;
|
|
175
|
+
while(!lastResultSizeIsLessThanPerPage) {
|
|
176
|
+
const { data } = await this.post(url, {
|
|
177
|
+
...options,
|
|
178
|
+
page: currentResult.length / perPage + 1,
|
|
179
|
+
});
|
|
180
|
+
page += 1;
|
|
181
|
+
currentResult = currentResult.concat(data);
|
|
182
|
+
lastResultSizeIsLessThanPerPage = data.length < perPage;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return currentResult;
|
|
186
|
+
}
|
|
164
187
|
};
|