Skip to content

Commit

Permalink
Adds support for excluding an appointment identifier from time slot g…
Browse files Browse the repository at this point in the history
…eneration
  • Loading branch information
craigpaul committed Jan 23, 2020
1 parent 707b0df commit 12c0735
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/resources/time-slot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ it('will set user filter using a number', async () => {
});
});

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

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

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

Expand Down Expand Up @@ -93,12 +101,14 @@ it('can string all filterable options together', async () => {
.for([1, 2])
.by(1)
.method(MeetingMethods.AT_LOCATION)
.excluding(1)
.supporting(['en'])
.visibility(Visibilities.ALL),
);

expected.toHaveProperty('filters', {
end: '2018-01-31',
exclusion: 1,
locales: ['en'],
location: 1,
method: MeetingMethods.AT_LOCATION,
Expand All @@ -121,13 +131,15 @@ it('can get time slots for no particular user', async () => {
.supporting(['fr', 'es'])
.for([1, 2])
.in(timezone)
.excluding(1)
.visibility(Visibilities.ALL)
.get();

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('times', {
params: {
end: '2018-01-31',
exclusion: 1,
location_id: 1,
service_id: [1, 2],
start: '2018-01-01',
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 @@ -5,6 +5,7 @@ import Conditional, { ConditionalResource } from './conditional';

export interface TimeSlotFilter {
end?: string;
exclusion?: number;
location?: number;
method?: number;
services?: number | number[];
Expand All @@ -17,6 +18,7 @@ export interface TimeSlotFilter {

export interface TimeSlotParameters {
end?: string;
exclusion?: number;
location_id?: number;
meeting_method?: number;
service_id?: number | number[];
Expand All @@ -34,6 +36,8 @@ export interface TimeSlotResource extends Resource, ConditionalResource {

by(user: number): this;

excluding(exclusion: number): this;

for(services: number | number[]): this;

in(timezone: string): this;
Expand Down Expand Up @@ -75,6 +79,12 @@ export default class TimeSlot extends Conditional implements TimeSlotResource {
return this;
}

public excluding(exclusion: number): this {
this.filters.exclusion = exclusion;

return this;
}

public for(services: number | number[]): this {
this.filters.services = services;

Expand All @@ -89,6 +99,10 @@ export default class TimeSlot extends Conditional implements TimeSlotResource {
start: this.filters.start,
};

if (this.filters.exclusion) {
params.exclusion = this.filters.exclusion;
}

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

0 comments on commit 12c0735

Please sign in to comment.