Commit a9931416 authored by Mark Stenglein's avatar Mark Stenglein

Linting and cleanup

parent fb25f4aa
Pipeline #712 failed with stage
in 43 seconds
......@@ -41,7 +41,8 @@ app.use(require('node-sass-middleware')({
app.use(express.static(path.join(__dirname, 'public')))
// Initialize the Database and Connection
var db = require(path.join(__dirname, 'models'))
// Not used currently so it's commented out
// var db = require(path.join(__dirname, 'models'))
// Populate initial data
require(path.join(__dirname, 'data'))
......
......@@ -81,7 +81,7 @@ var syncSections = function (semester) {
for (var z = 0; z < rawSections.classes.length; z++) {
var rawSection = rawSections.classes[z]
var sectionDateRange = rawSection.session_templates[0].date_range
var sectionDateRange = rawSection['session_templates'][0]['date_range']
var section = {
'crn': rawSection.crn,
......
......@@ -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
......@@ -43,10 +43,9 @@ module.exports.strClean = strClean
* @returns {Array|String}
*/
var strSplitClean = function (rawString, separator) {
// Validate input for separator
if (separator && separator.length !== 1) {
throw 'separator must be a single char'
throw { message: 'separator must be a single char' }
}
if (!separator) {
separator = ','
......
......@@ -22,7 +22,8 @@ module.exports = function (sequelize, DataTypes) {
unique: true,
fields: ['slug']
}
], classMethods: {
],
classMethods: {
associate: function (models) {
models.Semester.belongsTo(models.University, {foreignKey: 'university'})
models.Semester.hasMany(models.Section, {foreignKey: 'semester'})
......
......@@ -16,14 +16,13 @@ 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 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
// TODO: separate out into its own file
......@@ -40,8 +39,7 @@ router.get('/json/schools', function (req, res, next) {
db.University.findAll({
attributes: ['slug', 'name', 'website']
}).then(function (query) {
var schools
res.json(query)
res.json(query.dataValues)
})
})
......@@ -92,8 +90,8 @@ router.get('/json/classes/:SEMSLUG', function (req, res, next) {
router.get('/json/classes/:SEMESTER/:CRN', function (req, res, next) {
db.Section.findAll({
where: {
'crn' : req.params['CRN'],
'semester' : req.params(['SEMESTER'])
'crn': req.params['CRN'],
'semester': req.params(['SEMESTER'])
}
}).then(function (query) {
res.json(query)
......@@ -182,7 +180,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
})
// TODO: look into separating this out into it's own helper file
var makeCalendar = function(school, semester, sections) {
var makeCalendar = function (school, semester, sections) {
// Generate blank calendar
var cal = ical(
{
......@@ -221,9 +219,9 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
}
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) {
var hour = parseInt(time.substring(0, 2))
var min = parseInt(time.substring(3, 5))
if (time.substring(6, 8) === 'pm' && hour !== 12) {
hour += 12
}
return {'hour': hour, 'min': min}
......@@ -239,7 +237,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
startDateFinish.hour(endTime.hour)
startDateFinish.minute(endTime.min)
event = cal.createEvent({
var event = cal.createEvent({
uid: semester.get('slug') + '-' + section.get('crn'),
start: startDate.utc(true).toDate(),
end: startDateFinish.utc(true).toDate(),
......@@ -249,16 +247,19 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
until: endDate.utc(true).toDate()
},
summary: section.get('name'),
description: section.get('name') + ': ' + section.get('title') + ' (' + section.get('class_type') + ')\nSection: ' + section.get('section') + '\nInstructors: ' + section.get('instructor'),
description: (
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
return cal
......@@ -271,10 +272,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 'Invalid School Given!'
throw { message: 'Invalid School Given!' }
}
if (!queries[1]) {
throw 'Invalid Semester Given'
throw { message: '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