Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/doodle-node-cli / src / builders / meeting-options-builder.js
Size: Mime:
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,
};