From b42cf6e79bac302ffeb12e76a53ad1f6bd044da2 Mon Sep 17 00:00:00 2001 From: w33kly <117058340+w33kly@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:17:24 -0500 Subject: [PATCH] Update calls.js --- src/utils/api/calls.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/utils/api/calls.js b/src/utils/api/calls.js index 6077296..c60fd0c 100644 --- a/src/utils/api/calls.js +++ b/src/utils/api/calls.js @@ -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'); @@ -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) {