Skip to content

Commit

Permalink
Adds invitable filter to location and service resources
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Dec 3, 2018
1 parent 54320d3 commit 8e7de92
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/resources/location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ it('will set user filter using a string', async () => {
});
});

it('will set the invite only filter', async () => {
const resource = new Location(mockAxios);

expect(resource.invitable()).toHaveProperty('filters', {
invitable: 1,
});
});

it('will set the page we are on', async () => {
const resource = new Location(mockAxios);

Expand Down Expand Up @@ -92,13 +100,15 @@ it('can string all filterable options together', async () => {
.assigned()
.providing([1, 2])
.containing(1)
.invitable()
.sortBy('created')
.take(5)
.on(1),
);

expected.toHaveProperty('filters', {
assigned: true,
invitable: 1,
services: [1, 2],
user: 1,
});
Expand All @@ -123,6 +133,7 @@ it('can get locations with additional parameters', async () => {
.assigned()
.providing([1, 2])
.containing(1)
.invitable()
.sortBy('created')
.take(5)
.on(1)
Expand All @@ -132,6 +143,7 @@ it('can get locations with additional parameters', async () => {
expect(mockAxios.get).toHaveBeenCalledWith('locations', {
params: {
'filter[assigned]': true,
'filter[invite_only]': 1,
'filter[service]': [1, 2],
'filter[user]': 1,
limit: 5,
Expand Down
14 changes: 14 additions & 0 deletions src/resources/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { Filterable, Pageable } from '../index';

export interface LocationFilter {
assigned?: boolean;
invitable?: number;
services?: number | number[] | string | string[];
user?: number | string;
}

export interface LocationParameters {
assigned?: boolean;
invite_only?: number;
service?: number | number[] | string | string[];
user?: number | string;
}
Expand All @@ -20,6 +22,8 @@ export interface LocationResource extends Pageable {

containing(user: number | string): this;

invitable(): this;

providing(services: number | number[] | string | string[]): this;
}

Expand Down Expand Up @@ -73,6 +77,12 @@ export default class Location implements LocationResource {
return await this.client.get('locations', { params });
}

public invitable(): this {
this.filters.invitable = 1;

return this;
}

public on(page: number): this {
this.page = page;

Expand Down Expand Up @@ -104,6 +114,10 @@ export default class Location implements LocationResource {
params.assigned = this.filters.assigned;
}

if (typeof this.filters.invitable !== 'undefined') {
params.invite_only = this.filters.invitable;
}

if (typeof this.filters.services !== 'undefined') {
params.service = this.filters.services;
}
Expand Down
12 changes: 12 additions & 0 deletions src/resources/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ it('will set category filter using a string', async () => {
});
});

it('will set the invite only filter', async () => {
const resource = new Service(mockAxios);

expect(resource.invitable()).toHaveProperty('filters', {
invitable: 1,
});
});

it('will set the page we are on', async () => {
const resource = new Service(mockAxios);

Expand Down Expand Up @@ -93,6 +101,7 @@ it('can string all filterable options together', async () => {
.at(1)
.by(2)
.in(3)
.invitable()
.sortBy('created')
.take(5)
.on(1),
Expand All @@ -101,6 +110,7 @@ it('can string all filterable options together', async () => {
expected.toHaveProperty('filters', {
assigned: true,
category: 3,
invitable: 1,
location: 1,
user: 2,
});
Expand All @@ -126,6 +136,7 @@ it('can get services with additional parameters', async () => {
.at(1)
.by(2)
.in(3)
.invitable()
.sortBy('created')
.take(5)
.on(1)
Expand All @@ -136,6 +147,7 @@ it('can get services with additional parameters', async () => {
params: {
'filter[assigned]': true,
'filter[category]': 3,
'filter[invite_only]': 1,
'filter[location]': 1,
'filter[user]': 2,
limit: 5,
Expand Down
14 changes: 14 additions & 0 deletions src/resources/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { Filterable, Pageable } from '../index';
export interface ServiceFilter {
assigned?: boolean;
category?: number | string;
invitable?: number;
location?: number | string;
user?: number | string;
}

export interface ServiceParameters {
assigned?: boolean;
category?: number | string;
invite_only?: number;
location?: number | string;
user?: number | string;
}
Expand All @@ -25,6 +27,8 @@ export interface ServiceResource extends Pageable {
by(user: number | string): this;

in(category: number | string): this;

invitable(): this;
}

export default class Service implements ServiceResource {
Expand Down Expand Up @@ -89,6 +93,12 @@ export default class Service implements ServiceResource {
return this;
}

public invitable(): this {
this.filters.invitable = 1;

return this;
}

public on(page: number): this {
this.page = page;

Expand Down Expand Up @@ -118,6 +128,10 @@ export default class Service implements ServiceResource {
params.category = this.filters.category;
}

if (typeof this.filters.invitable !== 'undefined') {
params.invite_only = this.filters.invitable;
}

if (typeof this.filters.location !== 'undefined') {
params.location = this.filters.location;
}
Expand Down

0 comments on commit 8e7de92

Please sign in to comment.