From e6b63cd85f49f1792875672a6ef85ef0a01b660a Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Sat, 19 Oct 2024 17:08:55 +0300 Subject: [PATCH] Modify the updateMergedCalendar function to update all merged calendars --- server.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/server.js b/server.js index 76ebf89..8ed76b2 100644 --- a/server.js +++ b/server.js @@ -167,24 +167,23 @@ async function updateMergedCalendar(){ if (!calendarsData || !calendarsData.linkGroups) { throw new Error('Invalid calendars data structure'); } - console.log(calendarsData); + // Fetch calendar data for each link group - const promises = calendarsData.linkGroups.map((linkGroup) => { - return Promise.all(linkGroup.links.map((link) => { - return axios.get(link.url) - .then((response) => { - return { - data: response.data, - prefix: link.prefix, - override: link.override, - }; - }) - .catch((error) => { - console.error(error); - return null; - }); - })); - }); + for (const mergedCalendar of calendarsData.mergedCalendars) { + const promises = mergedCalendar.calendars.map((calendar) => { + return axios.get(calendar.url) + .then((response) => { + return { + data: response.data, + prefix: calendar.prefix, + override: calendar.override, + }; + }) + .catch((error) => { + console.error(error); + return null; + }); + }); const results = await Promise.all(promises); // Filter out any failed requests