Skip to content

Commit

Permalink
Adds preference model
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 17, 2018
1 parent 59a907d commit 4df6815
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/constants/days.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default class Days {
static get SUNDAY() {
return 0;
}

static get MONDAY() {
return 1;
}

static get TUESDAY() {
return 2;
}

static get WEDNESDAY() {
return 3;
}

static get THURSDAY() {
return 4;
}

static get FRIDAY() {
return 5;
}

static get SATURDAY() {
return 6;
}
}
26 changes: 26 additions & 0 deletions src/models/preference.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Days from '../constants/days';
import Preference from './preference';

it('sets the preference type to next available', async () => {
const preference = new Preference;

expect(preference.next()).toHaveProperty('attributes', {
day: null,
end: null,
start: null,
type: Preference.NEXT_AVAILABLE,
});
});

it('sets the preference type to next available', async () => {
const end = '1:00 PM';
const start = '9:00 AM';
const preference = new Preference;

expect(preference.on(Days.MONDAY).between(start, end)).toHaveProperty('attributes', {
day: Days.MONDAY,
end,
start,
type: Preference.CERTAIN_DAYS,
});
});
46 changes: 46 additions & 0 deletions src/models/preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Preferable } from '../types/models';
import { PreferableParameters } from '../types/parameters';

const NEXT_AVAILABLE = 1;
const CERTAIN_DAYS = 2;

export default class Preference implements Preferable {
protected attributes: PreferableParameters;

constructor() {
this.attributes = {
day: null,
end: null,
start: null,
type: null,
}
}

public between(start: string, end: string): this {
this.attributes.end = end;
this.attributes.start = start;

return this;
}

public next(): this {
this.attributes.type = NEXT_AVAILABLE;

return this;
}

public on(day: number): this {
this.attributes.day = day;
this.attributes.type = CERTAIN_DAYS;

return this;
}

static get NEXT_AVAILABLE() {
return NEXT_AVAILABLE;
}

static get CERTAIN_DAYS() {
return CERTAIN_DAYS;
}
}
8 changes: 8 additions & 0 deletions src/types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ export interface Answerable {

is(value: string): this;
}

export interface Preferable {
between(start: string, end: string): this;

next(): this;

on(day: number): this;
}
7 changes: 7 additions & 0 deletions src/types/parameters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export interface LocationParameters {
user?: number | string;
}

export interface PreferableParameters {
day?: number | null;
end?: string | null;
start?: string | null;
type?: number | null;
}

export interface QuestionParameters {
service?: number | number[] | string | string[];
}
Expand Down

0 comments on commit 4df6815

Please sign in to comment.