@autofleet/network 1.4.8-beta-1 → 1.4.8-beta-3
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 +5 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -165,21 +165,17 @@ module.exports = class Network {
|
|
|
165
165
|
async getAllPagesFromQueryEndpoint(url, options = {}) {
|
|
166
166
|
let currentResult = [];
|
|
167
167
|
|
|
168
|
-
if(!options.perPage) {
|
|
169
|
-
throw new Error('Missing perPage option');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const perPage = options.perPage;
|
|
173
168
|
let lastResultSizeIsLessThanPerPage = false;
|
|
174
169
|
let page = 0;
|
|
175
|
-
while(!lastResultSizeIsLessThanPerPage) {
|
|
176
|
-
const { data } = await this.
|
|
170
|
+
while(!lastResultSizeIsLessThanPerPage && page < 100) {
|
|
171
|
+
const { data } = await this.post(url, {
|
|
177
172
|
...options,
|
|
178
173
|
page: currentResult.length / perPage + 1,
|
|
179
174
|
});
|
|
175
|
+
const { rows, count } = data;
|
|
180
176
|
page += 1;
|
|
181
|
-
currentResult = currentResult.concat(
|
|
182
|
-
lastResultSizeIsLessThanPerPage =
|
|
177
|
+
currentResult = currentResult.concat(rows);
|
|
178
|
+
lastResultSizeIsLessThanPerPage = currentResult.length < count;
|
|
183
179
|
}
|
|
184
180
|
|
|
185
181
|
return currentResult;
|