Skip to content

Commit

Permalink
Converts filter output to match expected query string for services
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 30, 2018
1 parent 9d975f4 commit 26a3bb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/resources/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ it('can get services with additional parameters', async () => {
expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('services', {
params: {
filters: {
assigned: true,
category: 3,
location: 1,
user: 2,
},
'filter[assigned]': true,
'filter[category]': 3,
'filter[location]': 1,
'filter[user]': 2,
limit: 5,
page: 1,
sort: 'created',
Expand Down
5 changes: 3 additions & 2 deletions src/resources/service.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 ServiceFilter {
Expand Down Expand Up @@ -61,10 +62,10 @@ export default class Service implements ServiceResource {

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

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

if (this.limit) {
Expand Down

0 comments on commit 26a3bb4

Please sign in to comment.