Commit 3bec0b8c authored by Mark Stenglein's avatar Mark Stenglein Committed by Mark Stenglein

Add the majority of the scaffolding to get the class data out to the ical builder

  - next step is to actually write the ical generator :dancing_penguin:
  - I'm committing this through WebStorm's UI to try it out so I've no idea what could go wrong....just a heads up
parent db0f60df
Pipeline #698 failed with stage
in 42 seconds
......@@ -66,21 +66,90 @@ router.get('/json/classes/crn/:CRN', function (req, res, next) {
// ////////////////////////////////////////////////////////////////////////////
// ICAL API Section
router.get('/ical/:SCHOOL/:SEMSLUG/:CLASSES', function (req, res, next) {
/*
router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
// Extract arguments and setup empty objects for them
// Get School Information
var schoolSlug = req.params['SCHOOL']
var school = db.University
.findOne({
'attributes': ['slug', 'name', 'website'],
'where': {
'slug': schoolSlug
}
})
// Get Semester Information
var semSlug = req.params['SEMSLUG']
var classes = req.params['CLASSES']
*/
// Generate blank calendar
var cal = ical({domain: 'schedules.gmu.edu', name: 'SRCT Schedules Generated Calendar'})
res.set({
'Content-Type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'attachment; filename="' + ('calendar.ics') + '"'
var semester = db.Semester
.findOne({
'attributes': ['slug', 'name', 'university'],
'where': {
'slug': semSlug
}
})
// Get Section Information
var sectionArgs = req.params['SECTIONS']
var semesterSlugs = []
// Parse Section Args
sectionArgs.split(',').forEach(function (sectionArg) {
semesterSlugs.push(db.sequelize.escape(sectionArg))
})
res.send(cal.toString())
var sections = db.Section
.findAll({
'where': {
'semester': semSlug,
'crn': {
$in: semesterSlugs
}
}
})
var makeCalendar = function(school, semester, sections) {
// Generate blank calendar
var cal = ical(
{
domain: 'schedules.gmu.edu',
Please register or sign in to reply
prodId: '//Student Run Computing and Technology//Schedules//EN',
name: school.get('slug') + ' Class Schedule Fall 2016'
}
)
Please register or sign in to reply
return cal
}
// Wait for all the queries to finish
Promise
.all(
[school, semester, sections]
).then(function (queries) {
// Check for invalid responses and throw appropriate errors
if (!queries[0]) {
throw 'Invalid School Given!'
}
if (!queries[1]) {
throw 'Invalid Semester Given'
}
// Generate the calendar
var semesterCalendar = makeCalendar(queries[0], queries[1], queries[2])
  • I'd like to see if I can get a better solution for using the indexes here.....might not be a thing but I'll look at some point

Please register or sign in to reply
res.set({
'Content-Type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'attachment; filename="' + ('calendar.ics') + '"'
})
res.send(semesterCalendar.toString())
})
// Catch any errors and respond with grace
  • This really needs to be fleshed out to some proper error processing....in time

Please register or sign in to reply
.catch(function (error) {
console.log(error)
res.send(error)
})
})
module.exports = router
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment