Commit 3b4f0dff authored by Mark Stenglein's avatar Mark Stenglein

Linting and cleanup take 2

parent a9931416
Pipeline #713 failed with stage
in 43 seconds
......@@ -133,12 +133,12 @@ var syncSections = function (semester) {
* and or locations.
*/
for (var c = 0; c < rawSection.session_templates.length; c++) {
var session_template = rawSection.session_templates[c]
var sessionTemplate = rawSection.session_templates[c]
// raw value of the start/stop times (to be processed to time values)
var sessionTime = session_template.time;
var sessionTime = sessionTemplate.time;
(['M', 'T', 'W', 'R', 'F']).forEach(function (day) {
if (session_template.days.indexOf(day) > -1) {
if (sessionTemplate.days.indexOf(day) > -1) {
// if here then there is a session for the day
section[day + 'session'] = true
......@@ -162,16 +162,16 @@ var syncSections = function (semester) {
section[day + 'timeEnd'] = sessionTime.substr(endOffset, endLength)
// Note down location and type information
section[day + 'location'] = session_template.location
section[day + 'classType'] = session_template.class_type
section[day + 'location'] = sessionTemplate.location
section[day + 'classType'] = sessionTemplate.class_type
// If the instructor is not yet in the entire listing, add it.
// TODO: Make this tolerant of multiple instructors defined for
// one section. (ie. currently if you have 2 instructors in
// one section it'll search for all of them as one term and
// consequently add all of them to the full list.) Should
if (section.instructor.search(session_template.instructors) < 0) {
section.instructor += session_template.instructors
if (section.instructor.search(sessionTemplate.instructors) < 0) {
section.instructor += sessionTemplate.instructors
}
}
})
......
......@@ -11,9 +11,9 @@
* tl;dr: Forget staying thirsty, "Stay DRY, my friends."
*/
//var ical = require('ical-generator') // ical-generator library
//var config = require('config') // Site wide configs
//var db = require('../models') // Database Object
// var ical = require('ical-generator') // ical-generator library
// var config = require('config') // Site wide configs
// var db = require('../models') // Database Object
/*
* A brief note...since this is quite new and I don't know exactly how I want to
......@@ -22,6 +22,12 @@
* TODO: Make this not suck (dynamic loading of other files maybe?)
*/
var userException = function (message) {
this.message = message
this.name = 'userException'
}
module.exports.userException = userException
/**
* Strip all non alpha numeric characters from input.
*
......@@ -45,7 +51,7 @@ module.exports.strClean = strClean
var strSplitClean = function (rawString, separator) {
// Validate input for separator
if (separator && separator.length !== 1) {
throw { message: 'separator must be a single char' }
throw new userException('separator must be a single char')
}
if (!separator) {
separator = ','
......
......@@ -15,12 +15,12 @@ var express = require('express')
var path = require('path')
var router = express.Router()
var ical = require('ical-generator') // ical-generator library
var config = require('config') // Site wide configs
//var schoolSlugs = config.get('schoolSlugs') // Configured School Slugs
// var config = require('config') // Site wide configs
// var schoolSlugs = config.get('schoolSlugs') // Configured School Slugs
var db = require('models') // Database Object
var helpers = require(path.join(__dirname, '..', '..', 'helpers'))
var moment = require('moment')
//var _ = require('lodash')
// var _ = require('lodash')
// /////////////////////////////////////////////////////////////////////////////
// JSON API Definitions
......@@ -142,7 +142,6 @@ router.get('/json/classes/:SEMESTER/:CRN', function (req, res, next) {
* TODO: Remove the school part of this query...no need because of Sem Slugs
*/
router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
// Extract arguments and setup empty objects for them
// Get School Information
......@@ -184,16 +183,15 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
// Generate blank calendar
var cal = ical(
{
'domain' : 'schedules.gmu.edu',
'prodId' : '//Student Run Computing and Technology//Schedules//EN',
'name' : school.get('slug') + ' Class Schedule Fall 2016'
'domain': 'schedules.gmu.edu',
'prodId': '//Student Run Computing and Technology//Schedules//EN',
'name': school.get('slug') + ' Class Schedule Fall 2016'
}
)
cal.setTZ('America/New_York')
// Build the rest of the calendar
sections.forEach(function (section) {
// Fetch the start and end times
var startDate = moment(section.get('startDate'), 'MMM DD, YYYY')
var endDate = moment(section.get('endDate'), 'MMM DD, YYYY')
......@@ -218,7 +216,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
endDate = endDate.add(7, 'd')
}
var processTime = function(time) {
var processTime = function (time) {
var hour = parseInt(time.substring(0, 2))
var min = parseInt(time.substring(3, 5))
if (time.substring(6, 8) === 'pm' && hour !== 12) {
......@@ -237,7 +235,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
startDateFinish.hour(endTime.hour)
startDateFinish.minute(endTime.min)
var event = cal.createEvent({
cal.createEvent({
uid: semester.get('slug') + '-' + section.get('crn'),
start: startDate.utc(true).toDate(),
end: startDateFinish.utc(true).toDate(),
......@@ -248,16 +246,15 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
},
summary: section.get('name'),
description: (
section.get('name') + ': ' + section.get('title') + ' ('
+ section.get('class_type') + ')\nSection: '
+ section.get('section') + '\nInstructors: '
+ section.get('instructor')
section.get('name') + ': ' + section.get('title') + ' (' +
section.get('class_type') + ')\nSection: ' +
section.get('section') + '\nInstructors: ' +
section.get('instructor')
),
organizer: 'Mason SRCT <schedules@lists.srct.gmu.edu>',
url: 'https://schedules.gmu.edu'
})
})
})
// TODO: build the calendar events
......@@ -272,10 +269,10 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
).then(function (queries) {
// Check for invalid responses and throw appropriate errors
if (!queries[0]) {
throw { message: 'Invalid School Given!' }
throw new helpers.userException('Invalid School Given!')
}
if (!queries[1]) {
throw { message: 'Invalid Semester Given' }
throw new helpers.userException('Invalid Semester Given')
}
// Generate the calendar
......
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