From 318f585689f5cc984d6f774fa2882f1074bdbc07 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Wed, 23 Oct 2024 15:22:01 +0300 Subject: [PATCH] function to save calendar data to seperate .json files --- server.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 72d0f24..ea32e44 100644 --- a/server.js +++ b/server.js @@ -114,7 +114,7 @@ app.get('/calendar/:id', (req, res) => { }); //function to save CalendarData to calendars.json -function saveCalendarData(calendarId, linkGroupName, calendars) { +function saveCalendarDataJoint(calendarId, linkGroupName, calendars) { let calendarsData = { mergedCalendars: [] }; if (fs.existsSync(CALENDARS_FILE)) { try { @@ -143,6 +143,21 @@ function saveCalendarData(calendarId, linkGroupName, calendars) { console.error('Error writing to calendars file:', error); } } +//function to save calendar data to seperate .json files +function saveCalendarData(calendarId, linkGroupName, calendars) { + const calendarFile = `${MERGED_CALENDARS_DIR}/${calendarId}.json`; + const calendarData = { + id: calendarId, + linkGroupName: linkGroupName, + calendars: calendars + }; + + try { + fs.writeFileSync(calendarFile, JSON.stringify(calendarData, null, 2)); + } catch (error) { + console.error('Error writing to calendar file:', error); + } +} // Function to update the merged calendar async function updateMergedCalendars(calendarId){