Skip to content

Commit

Permalink
Allows an appointment to be rescheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
willik committed Oct 30, 2019
1 parent 88642e9 commit de18020
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/resources/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ export interface AppointmentParameters {
};
}

export interface RescheduleParameters {
data: {
attributes: {
start: string | undefined;
};
type: string;
};
meta?: {
notify?: {
client?: boolean;
user?: boolean;
};
};
}

export interface AppointmentResource extends Resource, ConditionalResource {
at(location: number): this;

Expand All @@ -66,6 +81,8 @@ export interface AppointmentResource extends Resource, ConditionalResource {

notify(notifications: AppointmentNotificationParameters): this;

reschedule(appointment: number): Promise<any>;

starting(start: string): this;

source(source: string): this;
Expand Down Expand Up @@ -138,6 +155,10 @@ export default class Appointment extends Conditional implements AppointmentResou
return this;
}

public async reschedule(appointment: number): Promise<any> {
return await this.client.patch(`appointments/${appointment}`, this.rescheduleParams());
}

public starting(start: string): this {
this.filters.start = start;

Expand Down Expand Up @@ -223,4 +244,26 @@ export default class Appointment extends Conditional implements AppointmentResou

return params;
}

protected rescheduleParams(): RescheduleParameters | object {
let params: RescheduleParameters = {
data: {
attributes: {
start: this.filters.start,
},
type: 'appointments',
},
};

if (this.filters.notifications) {
params = {
...params,
meta: {
notify: this.filters.notifications,
},
};
}

return params;
}
}

0 comments on commit de18020

Please sign in to comment.