diff options
Diffstat (limited to 'src/server/routes')
-rw-r--r-- | src/server/routes/getSchedule.js | 16 | ||||
-rw-r--r-- | src/server/routes/index.js | 26 |
2 files changed, 12 insertions, 30 deletions
diff --git a/src/server/routes/getSchedule.js b/src/server/routes/getSchedule.js index 2ade31a..fb78e97 100644 --- a/src/server/routes/getSchedule.js +++ b/src/server/routes/getSchedule.js @@ -22,10 +22,10 @@ const express = require('express'); const router = express.Router(); -const getScheduleData = require('../lib/schools/hetmml/getScheduleData'); -const getURLOfUser = require('../lib/schools/hetmml/getURLOfUser'); -const axios = require('../lib/schools/hetmml/axios'); -const parseSchedule = require('../lib/schools/hetmml/parseSchedule'); +const { getUsers } = require('../../shared/lib/db'); +const getURLOfUser = require('../../shared/lib/getURLOfUser'); +const axios = require('../../shared/lib/axios'); +const parseSchedule = require('../lib/parseSchedule'); // 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 @@ -46,14 +46,14 @@ function currentWeekNumber() { return 1 + Math.ceil((firstThursday - target) / 604800000); } -async function getSchedule(userType, userValue, week, scheduleType = 'dag') { - const { users } = await getScheduleData(); +async function getSchedule(userType, userName, week, scheduleType = 'dag') { + const users = await getUsers(); const user = users.filter(user_ => ( - user_.type === userType && user_.value === userValue + user_.type === userType && user_.name === userName ))[0]; if (!user) { - throw new Error(`${userType}/${userValue} is not in the user index.`); + throw new Error(`${userType}/${userName} is not in the user index.`); } if (!week) { diff --git a/src/server/routes/index.js b/src/server/routes/index.js index d647210..b0e86ee 100644 --- a/src/server/routes/index.js +++ b/src/server/routes/index.js @@ -21,31 +21,13 @@ const express = require('express'); const router = express.Router(); -const getScheduleData = require('../lib/schools/hetmml/getScheduleData'); +const { getUsers } = require('../../shared/lib/db'); /* GET home page. */ -router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], (req, res) => { - getScheduleData().then(({ users, dailyScheduleWeeks, basisScheduleWeeks }) => { - const isBeta = process.env.BETA === '1'; - - const flags = []; - if (isBeta) { - flags.push('BETA'); - flags.push('NO_FEATURE_DETECT'); - } else if (req.query.nfd != null) { - flags.push('NO_FEATURE_DETECT'); - } - - const flagsStr = `var FLAGS = ${JSON.stringify(flags)};`; - const usersStr = `var USERS = ${JSON.stringify(users)};`; - const dailyScheduleWeeksStr = `var DAGROOSTER_WEEKS = ${JSON.stringify(dailyScheduleWeeks)}`; - const basisScheduleWeeksStr = `var BASISROOSTER_WEEKS = ${JSON.stringify(basisScheduleWeeks)}`; - +router.get(['/', '/student/*', '/teacher/*', '/room/*', '/class/*'], (req, res) => { + getUsers().then((users) => { res.render('index', { - flagsStr, - usersStr, - dailyScheduleWeeksStr, - basisScheduleWeeksStr, + usersStr: JSON.stringify(users), }); }); // .catch(() => { |