Repository URL to install this package:
|
Version:
0.0.0-eb7f46753a3bdc ▾
|
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,
};