From 31507e13fd247ecd4a1b2dbd9f0d1fa73ef79eca Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 21 Mar 2022 09:18:29 +0000 Subject: [PATCH] Added delete test button and fixed link root --- routes/test.js | 20 +++++++++++++++----- views/test.hbs | 7 +++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/routes/test.js b/routes/test.js index 17a4588..d09c145 100644 --- a/routes/test.js +++ b/routes/test.js @@ -91,11 +91,20 @@ router.post('/testTemplate/add', async (req, res) => { return res.redirect('/testTemplate/add'); } - const tt = await a.createTestTemplate( - fields.get('name'), - fields.get('mark')); + try { + await a.createTestTemplate( + fields.get('name'), + fields.get('mark')); + } catch (e) { + return res.render('error', { + title: 'Stratos - Error', + current: 'Tests', + name: req.session.fullName, + msg: 'Could not create test template' + }); + } - return res.json(tt); + return res.redirect('/admin/test/add'); }); router.get(/test\/(.{36})(\/.*)?/, async (req, res, next) => { @@ -119,7 +128,7 @@ router.get(/test\/(.{36})(\/.*)?/, async (req, res, next) => { }); router.get('/test/:id', async (req, res) => { const t = await new Test(req.params.id); - const linkRoot = `/test/${t.id}`; + const linkRoot = `/admin/test/${t.id}`; return res.render('test', { title: `Stratos - ${t.template.name}`, @@ -130,6 +139,7 @@ router.get('/test/:id', async (req, res) => { subject: t.class.subject.name, maxMark: t.template.maxMark, reportsLink: `${linkRoot}/reports`, + deleteLink: `${linkRoot}/delete`, testResults: [ { mark: 50, percentage: 100, diff --git a/views/test.hbs b/views/test.hbs index 888dc1d..2b84344 100644 --- a/views/test.hbs +++ b/views/test.hbs @@ -1,4 +1,11 @@
+
+ {{#eq userType 'account'}} +
+ {{> button style='full' colour='primary' to=deleteLink content='Delete Test' size='lg'}} +
+ {{/eq}} +

Test Overview - {{ testName }}