Skip to content

Commit

Permalink
Converts filter output to match expected query string for users
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 30, 2018
1 parent 26a3bb4 commit 3bcc9a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/resources/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ it('can get users with additional parameters', async () => {
expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('users', {
params: {
filters: {
assigned: true,
location: 1,
service: [1, 2],
},
'filter[assigned]': true,
'filter[location]': 1,
'filter[service]': [1, 2],
limit: 5,
page: 1,
sort: 'created',
Expand Down
5 changes: 3 additions & 2 deletions src/resources/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AxiosInstance } from 'axios';

import { combine } from '../helpers/filters';
import { Filterable, Pageable } from '../index';

export interface UserFilter {
Expand Down Expand Up @@ -51,10 +52,10 @@ export default class User implements UserResource {

public async get(): Promise<any> {
const parameters = this.params();
const params: Filterable<UserParameters> = {};
let params: Filterable<UserParameters> = {};

if (Object.keys(parameters).length) {
params.filters = parameters;
params = combine(params, parameters);
}

if (this.limit) {
Expand Down

0 comments on commit 3bcc9a0

Please sign in to comment.