Skip to content

Commit 862f548

Browse files
Merge 99e1551 into ce1345a
2 parents ce1345a + 99e1551 commit 862f548

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

app/services/accounts.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed } from '@ember/object';
33
import { reads } from '@ember/object/computed';
44
import { task } from 'ember-concurrency';
55
import config from 'travis/config/environment';
6+
import fetchAll from 'travis/utils/fetch-all';
67
import { sortBy } from 'lodash';
78

89
const { billingEndpoint } = config;
@@ -28,8 +29,9 @@ export default Service.extend({
2829
}),
2930

3031
fetchOrganizations: task(function* () {
31-
const orgs = yield this.store.query('organization', {});
32-
return orgs;
32+
const allOrgs = yield fetchAll(this.store, 'organization', { include: '' });
33+
34+
return allOrgs;
3335
}).keepLatest(),
3436

3537
fetchSubscriptions: task(function* () {

app/utils/fetch-all.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
export default async function fetchAll(store, type, query = {}) {
2+
let allRecords = [];
3+
let currentQuery = Object.assign({}, query);
4+
let hasNextPage = true;
15

2-
let fetchAll = function (store, type, query) {
3-
return store.query(type, query).then((collection) => {
4-
let nextPage = collection.get('meta.pagination.next');
6+
while (hasNextPage) {
7+
const collection = await store.query(type, currentQuery);
8+
allRecords = allRecords.concat(collection.toArray());
9+
10+
const nextPage = collection.get('meta.pagination.next');
511
if (nextPage) {
6-
let { limit, offset } = nextPage;
7-
return fetchAll(store, type, Object.assign(query, { limit, offset }));
12+
currentQuery = { ...currentQuery, ...nextPage };
13+
} else {
14+
hasNextPage = false;
815
}
9-
});
10-
};
16+
}
1117

12-
export default fetchAll;
18+
return allRecords;
19+
}

0 commit comments

Comments
 (0)