forked from ryanmwangi/CalMerger
update the 'updateMergedCalendar function to include override feature
This commit is contained in:
parent
df9276c8a9
commit
3543489c3a
11
server.js
11
server.js
|
@ -114,6 +114,7 @@ async function updateMergedCalendar(){
|
||||||
return {
|
return {
|
||||||
data: response.data,
|
data: response.data,
|
||||||
prefix: calendar.prefix,
|
prefix: calendar.prefix,
|
||||||
|
override: calendar.override,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -132,11 +133,19 @@ async function updateMergedCalendar(){
|
||||||
const calendar = ical.parseICS(result.data);
|
const calendar = ical.parseICS(result.data);
|
||||||
Object.keys(calendar).forEach((key) => {
|
Object.keys(calendar).forEach((key) => {
|
||||||
const event = calendar[key];
|
const event = calendar[key];
|
||||||
|
if (result.override) {
|
||||||
|
mergedCal.push({
|
||||||
|
start: event.start,
|
||||||
|
end: event.end,
|
||||||
|
summary: result.prefix,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
mergedCal.push({
|
mergedCal.push({
|
||||||
start: event.start,
|
start: event.start,
|
||||||
end: event.end,
|
end: event.end,
|
||||||
summary: `${result.prefix} ${event.summary}`,
|
summary: `${result.prefix} ${event.summary}`,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -159,7 +168,7 @@ END:VEVENT
|
||||||
fs.writeFileSync(filename, icalString);
|
fs.writeFileSync(filename, icalString);
|
||||||
|
|
||||||
// Generate a unique URL for the merged calendar
|
// Generate a unique URL for the merged calendar
|
||||||
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
|
const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/${filename}`;
|
||||||
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
|
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue