Compare commits
3 Commits
026367fb17
...
e5202791ac
Author | SHA1 | Date |
---|---|---|
Ryan Mwangi | e5202791ac | |
Ryan Mwangi | 7dfa5875fe | |
Ryan Mwangi | 69a6718af8 |
22
server.js
22
server.js
|
@ -114,16 +114,34 @@ app.get('/calendar/:id', (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
//function to save CalendarData to calendars.json
|
//function to save CalendarData to calendars.json
|
||||||
function saveCalendarData(calendarId, calendars) {
|
function saveCalendarData(calendarId, linkGroupName, calendars) {
|
||||||
let calendarsData = { mergedCalendars: [] };
|
let calendarsData = { mergedCalendars: [] };
|
||||||
if (fs.existsSync(CALENDARS_FILE)) {
|
if (fs.existsSync(CALENDARS_FILE)) {
|
||||||
calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8'));
|
try {
|
||||||
|
const fileContent = fs.readFileSync(CALENDARS_FILE, 'utf8');
|
||||||
|
if (fileContent) {
|
||||||
|
calendarsData = JSON.parse(fileContent);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error reading calendars file:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ensure mergedCalendars array exists
|
||||||
|
if (!calendarsData.mergedCalendars) {
|
||||||
|
calendarsData.mergedCalendars = [];
|
||||||
|
}
|
||||||
|
|
||||||
calendarsData.mergedCalendars.push({
|
calendarsData.mergedCalendars.push({
|
||||||
id: calendarId,
|
id: calendarId,
|
||||||
|
linkGroupName: linkGroupName,
|
||||||
calendars: calendars
|
calendars: calendars
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2));
|
fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error writing to calendars file:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to update the merged calendar
|
// Function to update the merged calendar
|
||||||
|
|
Loading…
Reference in New Issue