summaryrefslogtreecommitdiff
path: root/helpers.js
diff options
context:
space:
mode:
authorRaphael Kabo <raphaelkabo@gmail.com>2022-04-23 16:09:57 +0100
committerRaphael Kabo <raphaelkabo@gmail.com>2022-04-23 16:09:57 +0100
commit80b0f2d4f76af2667507d69d25b06f1f9374f56a (patch)
treefafcecb1df44388ab2c12ac04d5a496a6d23ff15 /helpers.js
parent699ec4a110c1f67dcf2a3205d8c56579b2da898f (diff)
feat: Add event group ical feeds
Diffstat (limited to 'helpers.js')
-rw-r--r--helpers.js38
1 files changed, 37 insertions, 1 deletions
diff --git a/helpers.js b/helpers.js
index 168ef8c..f628a11 100644
--- a/helpers.js
+++ b/helpers.js
@@ -1,6 +1,10 @@
+const domain = require('./config/domain.js').domain;
+const siteName = require('./config/domain.js').sitename;
+
const mongoose = require('mongoose');
const Log = mongoose.model('Log');
var moment = require('moment-timezone');
+const icalGenerator = require('ical-generator');
// LOGGING
@@ -14,6 +18,38 @@ function addToLog(process, status, message) {
logEntry.save().catch(() => { console.log("Error saving log entry!") });
}
+function exportIcal(events) {
+ // Create a new icalGenerator... generator
+ const cal = icalGenerator({
+ domain: domain,
+ name: siteName
+ });
+ if (events instanceof Array === false) {
+ events = [ events ];
+ }
+ events.forEach(event => {
+ // Add the event to the generator
+ cal.createEvent({
+ start: moment.tz(event.start, event.timezone),
+ end: moment.tz(event.end, event.timezone),
+ timezone: event.timezone,
+ timestamp: moment(),
+ summary: event.name,
+ description: event.description,
+ organizer: {
+ name: event.hostName || "Anonymous",
+ email: event.creatorEmail || 'anonymous@anonymous.com',
+ },
+ location: event.location,
+ url: domain + '/' + event.id
+ });
+ });
+ // Stringify it!
+ const string = cal.toString();
+ return string;
+}
+
module.exports = {
- addToLog
+ addToLog,
+ exportIcal,
}