edit updateMergedCalendars function to read from the calendarFile

This commit is contained in:
Ryan Mwangi 2024-10-23 15:52:43 +03:00
parent e9569f9690
commit 3bbaeb2048
1 changed files with 2 additions and 9 deletions

View File

@ -164,17 +164,10 @@ async function updateMergedCalendars(calendarId){
try { try {
// Load calendar data from the individual JSON file // Load calendar data from the individual JSON file
const calendarFile = `${MERGED_CALENDARS_DIR}/${calendarId}.json`; const calendarFile = `${MERGED_CALENDARS_DIR}/${calendarId}.json`;
const calendarsData = JSON.parse(fs.readFileSync(calendarFile, 'utf8')); const calendarData = JSON.parse(fs.readFileSync(calendarFile, 'utf8'));
// Find the merged calendar with the specified ID
const mergedCalendar = calendarsData.mergedCalendars.find((calendar) => calendar.id === calendarId);
if (!mergedCalendar) {
throw new Error(`Merged calendar with ID ${calendarId} not found`);
}
// Fetch calendar data for each merged calendar // Fetch calendar data for each merged calendar
const promises = mergedCalendar.calendars.map((calendar) => { const promises = calendarData.calendars.map((calendar) => {
return axios.get(calendar.url) return axios.get(calendar.url)
.then((response) => { .then((response) => {
return { return {