Skip to content

Commit

Permalink
Updates documentation for responses in regards to cancelling an appoi…
Browse files Browse the repository at this point in the history
…ntment. Ensures response model is exportable
  • Loading branch information
coconutcraig committed Jul 15, 2019
1 parent 4cc7920 commit 1a5f451
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
61 changes: 57 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Set a relationship which will tell the API to use the given attendee model(s) wh
##### Example

```javascript
import { OpenApi, Attendee, Answer } from 'coconut-open-api-js';
import { OpenApi, Attendee, Answer, Response } from 'coconut-open-api-js';

class Appointments {
constructor() {
Expand Down Expand Up @@ -138,9 +138,22 @@ class Appointments {
.book();
}

async cancel({ appointment, attendee }) {
return this.api.appointments().cancel(appointment, attendee);
}()
async cancel(attributes) {
const { appointment, attendee } = attributes;

// We can optionally submit custom form responses when cancelling
// appointments by utilizing the Response and Attendee models.
const person = (new Attendee())
.as(attendee)
.responses([
(new Response()).for(1).is('an answer'),
(new Response()).for(2).selected(1),
]);

return this.api.appointments()
.with(person)
.cancel(appointment, attendee);
}

async fetch({ code, email, id }) {
return this.api.appointments().matching({ code, email, id }).get();
Expand All @@ -156,6 +169,10 @@ class Appointments {

Set a relationship which will tell the API to use the given answer model(s) for the attendee when booking an appointment.

- `as(identifier: number)`

Set the identifier for a given attendee.

- `located(details: LocatableDetailParameters)`

Set certain attributes on the attendee related to location details such as address and city.
Expand All @@ -176,6 +193,10 @@ Set any additional details the attendee has provided when booking an appointment

Set certain attributes on the attendee related to contact details such as cell phone and email.

- `responses(answers: ResponseModel | ResponseModel[])`

Set a relationship which will tell the API to use the given response model(s) for the attendee when cancelling an appointment.

- `speaks(language: string)`

Set the preferred locale of the attendee.
Expand Down Expand Up @@ -396,6 +417,38 @@ class Questions {
}
```

### Responses

##### Methods

- `for(question: number)`

Set an attribute to determine the identifier of the question being answer.

- `is(value: string)`

Set an attribute to determine the actual answer's value.

##### Example

```javascript
import { Response } from 'coconut-open-api-js';

class Responses {
static create({ question, value }) {
return (new Response())
.for(question)
.is(value);
}

static select({ question, option }) {
return (new Response())
.for(question)
.selected(option);
}
}
```

### Services

##### Methods
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Notifications from './constants/notifications';
import Answer from './models/answer';
import Attendee from './models/attendee';
import Preference from './models/preference';
import Response from './models/response';
import Appointment, { AppointmentResource } from './resources/appointment';
import Form, { FormResource } from './resources/form';
import Location, { LocationResource } from './resources/location';
Expand Down Expand Up @@ -46,7 +47,7 @@ export interface Sortable extends Resource {
sortBy(sortable: string): this;
}

export { Answer, Attendee, Days, Notifications, Preference };
export { Answer, Attendee, Days, Notifications, Preference, Response };

export class OpenApi {
protected appointment: AppointmentResource;
Expand Down

0 comments on commit 1a5f451

Please sign in to comment.