Skip to content

Commit

Permalink
Implements initial version of appointment resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 17, 2018
1 parent d74b703 commit 630c5b7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 6 deletions.
50 changes: 50 additions & 0 deletions src/resources/appointment.test.ts
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
import Appointment from './appointment';
import Attendee from '../models/attendee';
import { AppointmentNotificationParameters } from '../types/parameters';

it('can set the location property', async () => {
const appointment = new Appointment;

expect(appointment.at(1)).toHaveProperty('location', 1);
});

it('can set the user property', async () => {
const appointment = new Appointment;

expect(appointment.by(1)).toHaveProperty('user', 1);
});

it('can set the service property using a single number', async () => {
const appointment = new Appointment;

expect(appointment.for(1)).toHaveProperty('services', 1);
});

it('can set the service property using a multiple numbers', async () => {
const appointment = new Appointment;

expect(appointment.for([1, 2])).toHaveProperty('services', [1, 2]);
});

it('can set the notifications property', async () => {
const appointment = new Appointment;
const notifications: AppointmentNotificationParameters = {
client: true,
user: true,
};

expect(appointment.notify(notifications)).toHaveProperty('notifications', notifications);
});

it('can set a single attendee for the appointment', async () => {
const appointment = new Appointment;
const attendee = new Attendee;

expect(appointment.with(attendee)).toHaveProperty('attendees', [attendee]);
});

it('can set multiple attendees for the appointment', async () => {
const appointment = new Appointment;
const attendee = new Attendee;

expect(appointment.with([attendee, attendee])).toHaveProperty('attendees', [attendee, attendee]);
});
36 changes: 32 additions & 4 deletions src/resources/appointment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { AppointmentResource } from '../types/resources';
import { AttendeeModel } from '../types/models';
import { AppointmentMatcherParameters } from '../types/parameters';
import { AppointmentMatcherParameters, AppointmentNotificationParameters } from '../types/parameters';
import { AppointmentResource } from '../types/resources';

export default class Appointment implements AppointmentResource {
protected attendees: AttendeeModel[] | null;
protected location: number | null;
protected matchers: AppointmentMatcherParameters | null;
protected notifications: AppointmentNotificationParameters | null;
protected services: number | number[] | null;
protected user: number | null;

constructor() {
this.attendees = null;
this.location = null;
this.matchers = null;
this.notifications = null;
this.services = null;
this.user = null;
}

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

return this;
}

Expand All @@ -12,14 +30,18 @@ export default class Appointment implements AppointmentResource {
}

public by(user: number): this {
this.user = user;

return this;
}

public async cancel(appointment: number, attendee: number): Promise<any> {
return this;
//
}

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

return this;
}

Expand All @@ -28,14 +50,20 @@ export default class Appointment implements AppointmentResource {
}

public matching(matchers: AppointmentMatcherParameters): this {
this.matchers = matchers;

return this;
}

public notify(notifications: object): this {
public notify(notifications: AppointmentNotificationParameters): this {
this.notifications = notifications;

return this;
}

public with(attendees: AttendeeModel | AttendeeModel[]): this {
this.attendees = Array.isArray(attendees) ? attendees : [attendees];

return this;
}
}
5 changes: 5 additions & 0 deletions src/types/parameters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export interface AppointmentMatcherParameters {
id: string | number;
}

export interface AppointmentNotificationParameters {
client?: boolean;
user?: boolean;
}

export interface AnswerParameters {
question: number | null;
value: string | null;
Expand Down
4 changes: 2 additions & 2 deletions src/types/resources.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AttendeeModel } from './models';
import { AppointmentMatcherParameters } from './parameters';
import { AppointmentMatcherParameters, AppointmentNotificationParameters } from './parameters';

export interface AppointmentResource extends Resource {
at(location: number): this;
Expand All @@ -14,7 +14,7 @@ export interface AppointmentResource extends Resource {

matching(matchers: AppointmentMatcherParameters): this;

notify(notifications: object): this;
notify(notifications: AppointmentNotificationParameters): this;

with(attendees: AttendeeModel | AttendeeModel[]): this;
}
Expand Down

0 comments on commit 630c5b7

Please sign in to comment.