Skip to content

Commit

Permalink
Adds additional users filter to time slots
Browse files Browse the repository at this point in the history
  • Loading branch information
Olya Morozova authored and Olya Morozova committed Oct 20, 2020
1 parent b72216f commit cd58720
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ class Settings {

Set a filter which will tell the API to return time slots at the location matching the provided identifier.

- `attendedBy(users: number | number[])`

Set a filter which will tell the API to return time slots that match availability of the additional user matching the provided identifier.

- `between(start: string, end: string)`

Set a filter which will tell the API to return time slots between a given start and end date time string.
Expand Down Expand Up @@ -725,10 +729,11 @@ class TimeSlots {
this.api = new OpenApi();
}

async get({ appointment, end, location, service, start, user }) {
async get({ appointment, end, location, service, start, user, users }) {
return await this.api
.slots()
.at(location)
.attendedBy(users)
.by(user)
.for(service)
.between(start, end)
Expand Down
19 changes: 18 additions & 1 deletion src/resources/time-slot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ it('will set user filter using a number', async () => {
});
});

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

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

it('will set users filter using an array of numbers', async () => {
const resource = new TimeSlot(mockAxios);

expect(resource.attendedBy([1, 2])).toHaveProperty('filters', {
users: [1, 2],
});
});

it('will set an appointment exclusion filter using a number', async () => {
const resource = new TimeSlot(mockAxios);

Expand Down Expand Up @@ -98,6 +114,7 @@ it('can string all filterable options together', async () => {
resource
.between('2018-01-01', '2018-01-31')
.at(1)
.attendedBy([1, 2])
.for([1, 2])
.by(1)
.method(MeetingMethods.AT_LOCATION)
Expand All @@ -115,6 +132,7 @@ it('can string all filterable options together', async () => {
services: [1, 2],
start: '2018-01-01',
user: 1,
users: [1, 2],
visibility: Visibilities.ALL,
});
});
Expand Down Expand Up @@ -181,7 +199,6 @@ it('can get time slots for a specified user', async () => {
});
});


it('can conditionally set a filter', async () => {
const resource = new TimeSlot(mockAxios);

Expand Down
14 changes: 14 additions & 0 deletions src/resources/time-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export interface TimeSlotFilter {
timezone?: string;
locales?: string[];
user?: number;
users?: number | number[];
visibility?: number;
}

export interface TimeSlotParameters {
additional_staff_id?: number | number[];
end?: string;
exclusion?: number;
location_id?: number;
Expand All @@ -32,6 +34,8 @@ export interface TimeSlotParameters {
export interface TimeSlotResource extends Resource, ConditionalResource {
at(location: number): this;

attendedBy(users: number | number[]): this;

between(start: string, end: string): this;

by(user: number): this;
Expand Down Expand Up @@ -66,6 +70,12 @@ export default class TimeSlot extends Conditional implements TimeSlotResource {
return this;
}

public attendedBy(users: number | number[]): this {
this.filters.users = users;

return this;
}

public between(start: string, end: string): this {
this.filters.start = start;
this.filters.end = end;
Expand Down Expand Up @@ -119,6 +129,10 @@ export default class TimeSlot extends Conditional implements TimeSlotResource {
params.staff_id = this.filters.user;
}

if (this.filters.users) {
params.additional_staff_id = this.filters.users;
}

if (this.filters.visibility) {
params.visibility = this.filters.visibility;
}
Expand Down

0 comments on commit cd58720

Please sign in to comment.