Skip to content

Commit

Permalink
Update calls.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rossvc committed Oct 10, 2023
1 parent 7d989e1 commit b42cf6e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/utils/api/calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ exports.sendEmail = async function sendEmail(toEmail, email, subject, content) {
};

exports.getEvents = async function getEvents(pageToken = null, allEvents = []) {
let url = `https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?maxResults=50&key=${CALENDAR_API_KEY}`;
if (pageToken) {
url += `&pageToken=${pageToken}`;
}
const { data } = await axios.get(url);
const events = [];
data.items
let url = `https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?maxResults=50&key=${CALENDAR_API_KEY}`;
if (pageToken) {
url += `&pageToken=${pageToken}`;
}
const { data } = await axios.get(url);
const events = [];
data.items
.filter((obj) => obj?.start?.date || obj?.start?.dateTime)
.forEach((obj) => {
renameKey(obj.start, 'dateTime', 'date');
Expand All @@ -56,11 +56,10 @@ exports.getEvents = async function getEvents(pageToken = null, allEvents = []) {
});
});
allEvents.push(...events);
if (data.nextPageToken) {
return getEvents(data.nextPageToken, allEvents);
} else {
return { "events": _.sortBy(allEvents, (o) => moment(o.start)) };
}
if (data.nextPageToken) {
return getEvents(data.nextPageToken, allEvents);
}
return { events: _.sortBy(allEvents, (o) => moment(o.start)) };
};

exports.checkRecaptcha = async function checkRecaptcha(recaptchaToken) {
Expand Down

0 comments on commit b42cf6e

Please sign in to comment.