From 4df6815cab46d424c666379396935e680b7693fd Mon Sep 17 00:00:00 2001 From: Craig Paul Date: Sat, 17 Nov 2018 13:08:51 -0600 Subject: [PATCH] Adds preference model --- src/constants/days.ts | 29 ++++++++++++++++++++++ src/models/preference.test.ts | 26 ++++++++++++++++++++ src/models/preference.ts | 46 +++++++++++++++++++++++++++++++++++ src/types/models.d.ts | 8 ++++++ src/types/parameters.d.ts | 7 ++++++ 5 files changed, 116 insertions(+) create mode 100644 src/constants/days.ts create mode 100644 src/models/preference.test.ts create mode 100644 src/models/preference.ts diff --git a/src/constants/days.ts b/src/constants/days.ts new file mode 100644 index 0000000..899fcc8 --- /dev/null +++ b/src/constants/days.ts @@ -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; + } +} diff --git a/src/models/preference.test.ts b/src/models/preference.test.ts new file mode 100644 index 0000000..a655776 --- /dev/null +++ b/src/models/preference.test.ts @@ -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, + }); +}); diff --git a/src/models/preference.ts b/src/models/preference.ts new file mode 100644 index 0000000..90285b5 --- /dev/null +++ b/src/models/preference.ts @@ -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; + } +} diff --git a/src/types/models.d.ts b/src/types/models.d.ts index 6908fce..58ebfe6 100644 --- a/src/types/models.d.ts +++ b/src/types/models.d.ts @@ -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; +} diff --git a/src/types/parameters.d.ts b/src/types/parameters.d.ts index 2b456b4..208326f 100644 --- a/src/types/parameters.d.ts +++ b/src/types/parameters.d.ts @@ -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[]; }