Skip to content

Commit

Permalink
Add option to add additional query args to employee index request
Browse files Browse the repository at this point in the history
  • Loading branch information
fredbradley committed Feb 23, 2022
1 parent 65af850 commit 7dbba3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Controllers/HumanResourcesEmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function index(): Collection
{
$key = $this->institution->getConfigName() . 'hrEmployees.index';

$decoded = json_decode($this->pageRequest($this->endpoint, 1));
$decoded = json_decode($this->pageRequest($this->endpoint, 1, ['expand' => 'customFields']));
$items = collect($decoded->employees)->map(function ($item) {
return new Employee($item);
});

$totalCount = $decoded->totalCount;
$pageNumber = $decoded->page + 1;
while ($pageNumber <= $decoded->totalPages) {
$decoded = json_decode($this->pageRequest($this->endpoint, $pageNumber));
$decoded = json_decode($this->pageRequest($this->endpoint, $pageNumber, ['expand' => 'customFields']));

collect($decoded->employees)->map(function ($item) use ($items) {
$items->push(new Employee($item));
Expand Down
5 changes: 3 additions & 2 deletions src/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ abstract protected function setEndpoint(): void;
*
* @param string $url
* @param int $page
* @param array $queryArgs
* @return mixed
*
* @throws GuzzleException
*/
public function pageRequest(string $url, int $page)
public function pageRequest(string $url, int $page, array $queryArgs=[])
{
$response = $this->guzzle->request('GET', $url, [
'query' => ['page' => $page],
'query' => array_merge(['page' => $page], $queryArgs),
'headers' => $this->getHeaders(),
]);

Expand Down

0 comments on commit 7dbba3d

Please sign in to comment.