Skip to content

Commit

Permalink
Implements locatable filters for location resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Aug 19, 2019
1 parent e19141d commit 3a6d37c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/resources/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import { combine } from '../helpers/filters';
import { Filterable, Pageable } from '../index';
import Conditional, { ConditionalResource } from './conditional';

type LocatableLocationDetail = 'city' | 'country' | 'region';

export interface LocatableLocationParameters {
[key: string]: any;
city?: string;
country?: string;
region?: string;
}

export interface LocationFilter {
[key: string]: any;
assigned?: boolean;
invitable?: number;
services?: number | number[] | string | string[];
Expand All @@ -14,7 +24,10 @@ export interface LocationFilter {

export interface LocationParameters {
assignments?: boolean;
city?: string;
country?: string;
invite_only?: number;
province?: string;
service?: number | number[] | string | string[];
user?: number | string;
virtual?: number;
Expand Down Expand Up @@ -92,6 +105,16 @@ export default class Location extends Conditional implements LocationResource {
return this;
}

public located(details: LocatableLocationParameters): this {
const keys = Object.keys(details) as LocatableLocationDetail[];

keys.map(key => {
this.filters[key] = details[key];
});

return this;
}

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

Expand Down Expand Up @@ -135,10 +158,22 @@ export default class Location extends Conditional implements LocationResource {
params.assignments = this.filters.assigned;
}

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

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

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

if (typeof this.filters.region !== 'undefined') {
params.province = this.filters.region;
}

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

0 comments on commit 3a6d37c

Please sign in to comment.