Skip to content

Commit

Permalink
Moves relationships away from filter setup to relationship setup. Add…
Browse files Browse the repository at this point in the history
…s attendee relationship setter
  • Loading branch information
coconutcraig committed Nov 19, 2018
1 parent 5588aa7 commit bfe94df
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
22 changes: 16 additions & 6 deletions src/resources/wait-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
import mockAxios from 'axios';

import Attendee from '../models/attendee';
import WaitList from './wait-list';

it('will set location filter using a number', async () => {
const resource = new WaitList(mockAxios);

expect(resource.at(1)).toHaveProperty('filters', {
expect(resource.at(1)).toHaveProperty('relationships', {
location: 1,
});
});

it('will set location filter using a numeric string', async () => {
const resource = new WaitList(mockAxios);

expect(resource.at('1')).toHaveProperty('filters', {
expect(resource.at('1')).toHaveProperty('relationships', {
location: '1',
});
});

it('will set service filter using a number', async () => {
const resource = new WaitList(mockAxios);

expect(resource.seeking(1)).toHaveProperty('filters', {
expect(resource.seeking(1)).toHaveProperty('relationships', {
service: 1,
});
});

it('will set service filter using a numeric string', async () => {
const resource = new WaitList(mockAxios);

expect(resource.seeking('1')).toHaveProperty('filters', {
expect(resource.seeking('1')).toHaveProperty('relationships', {
service: '1',
});
});

it('will set user filter using a number', async () => {
const resource = new WaitList(mockAxios);

expect(resource.with(1)).toHaveProperty('filters', {
expect(resource.with(1)).toHaveProperty('relationships', {
user: 1,
});
});

it('will set user filter using a numeric string', async () => {
const resource = new WaitList(mockAxios);

expect(resource.with('1')).toHaveProperty('filters', {
expect(resource.with('1')).toHaveProperty('relationships', {
user: '1',
});
});
Expand Down Expand Up @@ -74,6 +75,15 @@ it('will set the includes parameter using a comma separated string', async () =>
});
});

it('can set an attendee for the wait list request', async () => {
const resource = new WaitList(mockAxios);
const attendee = new Attendee;

expect(resource.for(attendee)).toHaveProperty('relationships', {
attendee,
});
});

it('can create a new wait list request for a given client using only required attributes', async () => {
//
});
Expand Down
18 changes: 12 additions & 6 deletions src/resources/wait-list.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { AxiosInstance } from 'axios';

import { WaitListFilter } from '../types/filters';
import { AttendeeModel, PreferenceModel } from '../types/models';
import { IncludableParameters, WaitListUrlParameters } from '../types/parameters';
import { WaitListRelationship } from '../types/relationships';
import { WaitListResource } from '../types/resources';

export default class WaitList implements WaitListResource {
protected client: AxiosInstance;
protected filters: WaitListFilter;
protected parameters: WaitListUrlParameters;
protected relationships: WaitListRelationship;

constructor(client: AxiosInstance) {
this.client = client;
this.filters = {};
this.parameters = {};
this.relationships = {};
}

public async add(): Promise<any> {
//
}

public at(location: number | string): this {
this.filters.location = location;
this.relationships.location = location;

return this;
}
Expand All @@ -44,6 +44,8 @@ export default class WaitList implements WaitListResource {
}

public for(attendee: AttendeeModel): this {
this.relationships.attendee = attendee;

return this;
}

Expand All @@ -57,14 +59,18 @@ export default class WaitList implements WaitListResource {
return this;
}

public provided(notes: string): this {
return this;
}

public async remove(list: number | string): Promise<any> {
const { client } = this.parameters;

return await this.client.delete(`clients/${client}/requests/${list}`);
}

public seeking(service: number | string): this {
this.filters.service = service;
this.relationships.service = service;

return this;
}
Expand All @@ -74,7 +80,7 @@ export default class WaitList implements WaitListResource {
}

public with(user: number | string): this {
this.filters.user = user;
this.relationships.user = user;

return this;
}
Expand Down
6 changes: 0 additions & 6 deletions src/types/filters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,3 @@ export interface UserFilter {
services?: number | number[] | string | string[];
location?: number | string;
}

export interface WaitListFilter {
location?: number | string;
service?: number | string;
user?: number | string;
}
7 changes: 7 additions & 0 deletions src/types/relationships.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ import { AttendeeModel } from './models';
export interface AppointmentRelationship {
attendees?: AttendeeModel[] | []
}

export interface WaitListRelationship {
attendee?: AttendeeModel;
location?: number | string;
service?: number | string;
user?: number | string;
}
2 changes: 2 additions & 0 deletions src/types/resources.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export interface WaitListResource {

prefers(preferences: PreferenceModel | PreferenceModel[]): this;

provided(notes: string): this;

remove(list: number | string): Promise<any>;

seeking(service: number | string): this;
Expand Down

0 comments on commit bfe94df

Please sign in to comment.