diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-09-13 16:28:53 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-09-13 16:28:53 +0200 |
commit | 3fb86482404e11942cd83c3500a297a3991db0e4 (patch) | |
tree | c5e7261de72c2b7f871580784525d06d036a6219 /routes/getSchedule.js | |
parent | 5aac32f72eca8c66e879583ce653d07bb3c7370f (diff) |
Restructure project
Diffstat (limited to 'routes/getSchedule.js')
-rw-r--r-- | routes/getSchedule.js | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/routes/getSchedule.js b/routes/getSchedule.js deleted file mode 100644 index f6c3cb6..0000000 --- a/routes/getSchedule.js +++ /dev/null @@ -1,55 +0,0 @@ -const express = require('express') -const router = express.Router() -const request = require('request') -const iconv = require('iconv-lite') - -const getUserIndex = require('../lib/getUserIndex') -const getURLOfUser = require('../lib/getURLOfUser') - -// copied from http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/untisscripts.js, -// were using the same code as they do to be sure that we always get the same -// week number. -function getWeekNumber (target) { - const dayNr = (target.getDay() + 6) % 7 - target.setDate(target.getDate() - dayNr + 3) - const firstThursday = target.valueOf() - target.setMonth(0, 1) - if (target.getDay() !== 4) { - target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7) - } - - return 1 + Math.ceil((firstThursday - target) / 604800000) -} - -router.get('/:type/:value', function (req, res, next) { - getUserIndex().then(users => { - const { type, value } = req.params - let { week } = req.query - const user = - users.filter(user => user.type === type && user.value === value)[0] - - if (!user) { - next(new Error(`${type}${value} is not in the user index.`)) - } - - if (!week) { - week = getWeekNumber(new Date()) - } - - const { index } = user - - const url = getURLOfUser(type, index, week) - - request(url, { encoding: null }, function (err, data) { - if (err) { - next(err) - return - } - - const utf8Body = iconv.decode(data.body, 'ISO-8859-1') - res.status(data.statusCode).end(utf8Body) - }) - }) -}) - -module.exports = router |