Skip to content

Commit

Permalink
Adds call to add one or more attendees to an existing appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
craigpaul committed Nov 22, 2019
1 parent f2c48e6 commit 43e250a
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/resources/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,22 @@ export interface RescheduleParameters {
};
}

interface AddSingleAttendeeParameter {
attributes: {
email: string,
first_name: string,
last_name: string,
},
type: string,
}

export interface AddAttendeeParameters {
data: AddSingleAttendeeParameter[],
}

export interface AppointmentResource extends Resource, ConditionalResource {
add(appointment: number): Promise<any>;

at(location: number): this;

book(): Promise<any>;
Expand Down Expand Up @@ -137,6 +152,14 @@ export default class Appointment extends Conditional implements AppointmentResou
this.utm = {};
}

public async add(appointment: number): Promise<any> {
return await this.client.put(`appointments/${appointment}/attendees`, this.addParams(), {
headers: {
'Content-Type': 'application/json; ext=bulk',
},
});
}

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

Expand Down Expand Up @@ -233,6 +256,26 @@ export default class Appointment extends Conditional implements AppointmentResou
return this;
}

protected addParams(): AddAttendeeParameters | object {
const attendees = (this.relationships.attendees as AttendeeModel[]).map(
(attendee: AttendeeModel): object => {
return attendee.transform();
}
);

return {
data: attendees,
}
}

protected hasUtm(): boolean {
return !!(this.utm.campaign)
|| !!(this.utm.content)
|| !!(this.utm.medium)
|| !!(this.utm.source)
|| !!(this.utm.term);
}

protected params(): AppointmentParameters | object {
if (this.relationships.attendees.length === 0) {
return {};
Expand Down Expand Up @@ -301,14 +344,6 @@ export default class Appointment extends Conditional implements AppointmentResou
return params;
}

protected hasUtm(): boolean {
return !!(this.utm.campaign)
|| !!(this.utm.content)
|| !!(this.utm.medium)
|| !!(this.utm.source)
|| !!(this.utm.term);
}

protected rescheduleParams(appointment: number): RescheduleParameters | object {
let params: RescheduleParameters = {
data: {
Expand Down

0 comments on commit 43e250a

Please sign in to comment.