diff options
author | Raphael Kabo <raphaelkabo@gmail.com> | 2022-04-23 16:09:57 +0100 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@gmail.com> | 2022-04-23 16:09:57 +0100 |
commit | 80b0f2d4f76af2667507d69d25b06f1f9374f56a (patch) | |
tree | fafcecb1df44388ab2c12ac04d5a496a6d23ff15 /helpers.js | |
parent | 699ec4a110c1f67dcf2a3205d8c56579b2da898f (diff) |
feat: Add event group ical feeds
Diffstat (limited to 'helpers.js')
-rw-r--r-- | helpers.js | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -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, } |