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 / apis / schedex.js
Size: Mime:
const fetch = require('fetch-everywhere');
const { errorHandler, responseHandler } = require('./fetch');
const { DOODLE_ENVS, verboseLogging } = require('../constants');
const SchedulingAttempt = require('../builders/scheduling-attempt-builder');

/**
 * Create a SchedEx Scheduling Attempt.
 *
 * @param {String} target - staging, devbox, etc
 * @param {String} accessToken - The users JWT token
 * @param {Object} meetingInfo - the meeting info object
 * @returns {Promise}
 */
const createSchedulingAttempt = (target, accessToken, meetingInfo = {}) => {
  const headers = {
    Authorization: `Bearer ${accessToken}`,
    'Content-Type': 'application/json',
  };

  const { meetingType, meetingTitle, locationText, descriptionText, videoConferencing, allDay } = meetingInfo;

  const body = new SchedulingAttempt()
    .withMeetingTitle(meetingTitle)
    .withDescriptionText(descriptionText)
    .withMeetingType(meetingType)
    .withAllDayOptions(allDay)
    .withLocationText(locationText)
    .withVideoConferencingProvider(videoConferencing)
    .build();

  const { schedexApiBase } = DOODLE_ENVS[target];
  const url = `${schedexApiBase}/attempts`;

  if (verboseLogging) {
    console.log(`POST: ${url}`);
  }

  return fetch(url, { method: 'POST', headers, body: JSON.stringify(body) })
    .then(responseHandler)
    .catch(errorHandler);
};

module.exports = {
  createSchedulingAttempt,
};