Repository URL to install this package:
|
Version:
0.0.0-eb7f46753a3bdc ▾
|
const moment = require('moment');
const OPTION_STRATEGIES = {
NEXT_THREE_DAYS: 'NEXT_THREE_DAYS',
};
function getTodayAtThree() {
const threeOClock = { hour: 15, minute: 0 };
return moment().set(threeOClock);
}
function getGeneratedOption(options = {}, datetime) {
const { allDay, collisionAllowed } = options;
const startAt = datetime.toISOString();
const endAt = allDay ? startAt : datetime.add(1, 'hours').toISOString();
return {
allDay,
collisionAllowed,
endAt,
startAt,
};
}
class MeetingOptions {
constructor() {
this.allDay = false;
this.options = [];
this.collisionAllowed = true;
this.generationStrategy = OPTION_STRATEGIES.NEXT_THREE_DAYS;
}
withGenerationStrategy(strategy) {
this.generationStrategy = strategy;
return this;
}
withAllDayOptions(value) {
this.allDay = value;
return this;
}
build() {
if (this.generationStrategy === OPTION_STRATEGIES.NEXT_THREE_DAYS) {
const tomorrow = getTodayAtThree().add(1, 'days');
const dayAfterTomorrow = getTodayAtThree().add(2, 'days');
const thirdDay = getTodayAtThree().add(3, 'days');
this.options.push(getGeneratedOption(this, tomorrow));
this.options.push(getGeneratedOption(this, dayAfterTomorrow));
this.options.push(getGeneratedOption(this, thirdDay));
}
return this.options;
}
}
module.exports = {
OPTION_STRATEGIES,
MeetingOptions,
};