Skip to content

Commit

Permalink
Fix getNextPage in User Service
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Aug 8, 2024
1 parent f3f5220 commit 3705857
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v7.5.1 (Next Release)

- Fixes `getNextPage` function in User Service

## v7.5.0 (2024-07-24)

- Adds new `Claim` service for filing claims on EasyPost shipments and insurances
Expand Down
24 changes: 24 additions & 0 deletions src/services/user_service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import baseService from './base_service';
import EndOfPaginationError from '../errors/general/end_of_pagination_error';

export default (easypostClient) =>
/**
Expand Down Expand Up @@ -145,4 +146,27 @@ export default (easypostClient) =>
const url = 'users/children';
return this._getNextPage(url, 'children', children, pageSize);
}

static async _getNextPage(url, key, collection, pageSize = null, optionalParams = {}) {
const collectionArray = collection[key];
if (collectionArray == undefined || collectionArray.length == 0 || !collection.has_more) {
throw new EndOfPaginationError();
}

const defaultParams = collection._params ?? collectionArray[0]._params ?? {};

const params = {
...defaultParams,
page_size: defaultParams.page_size ?? pageSize,
after_id: collectionArray[collectionArray.length - 1].id,
...optionalParams,
};

const response = await this._all(url, params);
if (response == undefined || response[key].length == 0) {
throw new EndOfPaginationError();
}

return response;
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3705857

Please sign in to comment.