function to save calendar data to seperate .json files

This commit is contained in:
Ryan Mwangi 2024-10-23 15:22:01 +03:00
parent 3578ea262d
commit 318f585689

View file

@ -114,7 +114,7 @@ app.get('/calendar/:id', (req, res) => {
}); });
//function to save CalendarData to calendars.json //function to save CalendarData to calendars.json
function saveCalendarData(calendarId, linkGroupName, calendars) { function saveCalendarDataJoint(calendarId, linkGroupName, calendars) {
let calendarsData = { mergedCalendars: [] }; let calendarsData = { mergedCalendars: [] };
if (fs.existsSync(CALENDARS_FILE)) { if (fs.existsSync(CALENDARS_FILE)) {
try { try {
@ -143,6 +143,21 @@ function saveCalendarData(calendarId, linkGroupName, calendars) {
console.error('Error writing to calendars file:', error); 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 // Function to update the merged calendar
async function updateMergedCalendars(calendarId){ async function updateMergedCalendars(calendarId){