-
-
Save maenthoven/346caf5d122c61a8015427bb341080e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
const Schema = mongoose.Schema; | |
const Promise = require('bluebird'); | |
mongoose.Promise = Promise; | |
const CalendarEntrySchema = new Schema({ | |
url: String, | |
game: { | |
id: Number, | |
name: String | |
}, | |
type: { | |
type: String, | |
uppercase: true, | |
default: 'RELEASE', | |
enum: ['RELEASE', 'EVENT'] | |
}, | |
imageSrc: String, | |
startDate: {type: Date, required: true, index: true}, | |
endDate: Date, | |
tagLine: {type: String, required: true, index: {unique: true}}, | |
priority: {type: Number, default: 0}, | |
additionalInfo: Object | |
}, {timestamps: true}); | |
const CalendarEntry = mongoose.model('CalendarEntry', CalendarEntrySchema, 'CalendarEntry'); | |
module.exports = CalendarEntry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ical = require('ical-generator'); | |
function saveCalendarICal(data, items) { | |
const icalConfig = { | |
domain: 'opencritic.com', | |
prodId: { | |
company: 'OpenCritic.com', | |
product: data.title | |
}, | |
name: 'OpenCritic Gaming Calendar' | |
}; | |
const events = items.filter(item => item.type === 'RELEASE') | |
.map(item => { | |
item.startDate = new Date(item.startDate); | |
return { | |
start: item.startDate, | |
end: new Date(item.startDate.getTime() + 3600000), | |
summary: item.tagLine + ' Release', | |
url: item.url, | |
allDay: true, | |
description: item.description | |
} | |
}).concat( | |
items.filter(item => item.type === 'EVENT') | |
.map(item => { | |
item.startDate = new Date(item.startDate); | |
item.endDate = new Date(item.endDate); | |
return { | |
start: item.startDate, | |
end: new Date(item.endDate.getTime() + 3600000), | |
summary: item.tagLine, | |
url: item.url | |
} | |
})); | |
const calendar = ical(icalConfig); | |
return calendar.events(events).toString(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment