Skip to content

Commit

Permalink
PS-536: Added recaptcha token as an optional parameter (#48)
Browse files Browse the repository at this point in the history
* PS-536: Added recaptcha token as an optional parameter

* Fix

* sfds

* dsfsd

* dfh

* Formatting changes
  • Loading branch information
CodyAntcliffeCoconut authored Jul 7, 2022
1 parent 9c55159 commit 10aa641
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/models/attendee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AttendeeParameters {
notes?: string;
phone?: string;
postcode?: string;
recaptcha_token?: string | null;
region?: string;
responses?: ResponseModel[] | [];
timezone?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/resources/appointment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ it('can book an appointment with all available parameters', async () => {
.source('test source')
.term('test term')
.actingAs(10)
.recaptcha('foo')
.withInviteOnly()
.withinUserCategory(1)
.withoutMeetingLink()
Expand Down Expand Up @@ -350,6 +351,7 @@ it('can book an appointment with all available parameters', async () => {
invite_only_resources: 1,
location_id: 1,
meeting_method: PHONE_CALL,
recaptcha_token: 'foo',
service_id: [2, 3],
staff_category_id: 1,
staff_id: 4,
Expand Down
15 changes: 14 additions & 1 deletion src/resources/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface AppointmentFilter {
matchers?: AppointmentMatcherParameters;
method?: number;
notifications?: AppointmentNotificationParameters;
recaptcha_token?: string | null;
services?: number | number[];
shortcut?: number;
skip_meeting_link_generation?: boolean;
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface AppointmentParameters {
invite_only_resources?: number;
location_id: number | undefined;
meeting_method?: number;
recaptcha_token?: string;
service_id: number | number[] | undefined;
staff_category_id?: number;
staff_id: number | null;
Expand Down Expand Up @@ -148,6 +150,8 @@ export interface AppointmentResource extends Resource, ConditionalResource {

notify(notifications: AppointmentNotificationParameters): this;

recaptcha(recaptchaToken: string): this;

reschedule(appointment: number, code: string): Promise<any>;

shortcut(shortcut: number): this;
Expand Down Expand Up @@ -276,7 +280,6 @@ export default class Appointment extends Conditional implements AppointmentResou

return await this.client.post('appointments', formData);
}

return await this.client.post('appointments', this.params());
}

Expand Down Expand Up @@ -347,6 +350,12 @@ export default class Appointment extends Conditional implements AppointmentResou
return this;
}

public recaptcha(recaptchaToken: string): this {
this.filters.recaptcha_token = recaptchaToken;

return this;
}

public async reschedule(appointment: number, code: string): Promise<any> {
return await this.client.patch(`appointments/${appointment}?code=${code}`, this.rescheduleParams(appointment));
}
Expand Down Expand Up @@ -491,6 +500,10 @@ export default class Appointment extends Conditional implements AppointmentResou
supported_locale: this.filters.locale || null,
};

if (this.filters.recaptcha_token) {
params.data.attributes.recaptcha_token = this.filters.recaptcha_token;
}

if (this.filters.user) {
params.data.attributes.staff_id = this.filters.user;
}
Expand Down

0 comments on commit 10aa641

Please sign in to comment.