1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:59:28 +00:00

Make test and class validation more general

This commit is contained in:
2022-03-14 09:42:33 +00:00
parent e1de67266c
commit 0298c81f51
2 changed files with 16 additions and 5 deletions

View File

@@ -56,10 +56,10 @@ router.post('/class/add', async (req, res) => {
res.redirect(`/admin/class/${c.id}/members`);
});
router.get('/class/:id', async (req, res) => {
router.get(/class\/(.{36})(\/.*)?/, async (req, res, next) => {
let c;
try {
c = await new Class(req.params.id);
c = await new Class(req.params[0]);
} catch (e) {
return res.status(400).render('error', {
title: 'Stratos - Error',
@@ -73,7 +73,12 @@ router.get('/class/:id', async (req, res) => {
if (!await c.hasAccess(await new User(null, req.session.userId)))
return res.redirect('/admin/classes');
const linkRoot = `/class/${c.id}`;
next();
});
router.get('/class/:id', async (req, res) => {
const c = await new Class(req.params.id);
const linkRoot = `/admin/class/${c.id}`;
const upcomingTests = await c.getTests({ range: 'after' });
const recentTests = await c.getTests({ range: 'before' });
const testCount = recentTests.length + upcomingTests.length;
@@ -90,6 +95,8 @@ router.get('/class/:id', async (req, res) => {
contactLink: `${linkRoot}/contact`,
testsLink: `${linkRoot}/tests`,
reportsLink: `${linkRoot}/reports`,
deleteLink: `${linkRoot}/delete`,
userType: req.session.userType,
stats: [
{
value: testCount,

View File

@@ -98,10 +98,10 @@ router.post('/testTemplate/add', async (req, res) => {
return res.json(tt);
});
router.get('/test/:id', async (req, res) => {
router.get(/test\/(.{36})(\/.*)?/, async (req, res, next) => {
let t;
try {
t = await new Test(req.params.id);
t = await new Test(req.params[0]);
} catch (e) {
return res.status(400).render('error', {
title: 'Stratos - Error',
@@ -115,6 +115,10 @@ router.get('/test/:id', async (req, res) => {
if (!await t.hasAccess(await new User(null, req.session.userId)))
return res.redirect('/admin/tests');
next();
});
router.get('/test/:id', async (req, res) => {
const t = await new Test(req.params.id);
const linkRoot = `/test/${t.id}`;
return res.render('test', {