Add better error management for seasons
parent
f9ac3f49cd
commit
51783c5dec
|
@ -68,17 +68,25 @@ router.post('/game', checkLoginStatus.user, async function(req, res, next) {
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/season', checkLoginStatus.admin, function(req, res, next) {
|
router.get('/season', checkLoginStatus.admin, function(req, res, next) {
|
||||||
res.render('manage/addseason', { title: 'Add Season', currentYear : (new Date()).getFullYear(), userLoggedIn: !!req.user });
|
res.render('manage/addseason', { title: 'Add Season', currentYear : (new Date()).getFullYear(), userLoggedIn: !!req.user, message: req.flash('error') });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/season', checkLoginStatus.admin, function(req, res, next) {
|
router.post('/season', checkLoginStatus.admin, async function(req, res, next) {
|
||||||
const year = req.body['year'];
|
try {
|
||||||
|
const year = req.body['year'];
|
||||||
|
|
||||||
const seasonID = req.body['season'];
|
const seasonID = req.body['season'];
|
||||||
const remove = req.body['remove'];
|
const remove = req.body['remove'];
|
||||||
|
|
||||||
if(remove) seasons.remove(seasonID).then(res.redirect('/manage'));
|
if(remove) await seasons.remove(seasonID);
|
||||||
else seasons.add(year).then(res.redirect("/manage"));
|
else await seasons.add(year);
|
||||||
|
|
||||||
|
res.redirect('/manage');
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
req.flash("error", "An error has occurred.");
|
||||||
|
res.redirect('/manage/season');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/sport', checkLoginStatus.admin, function(req, res, next) {
|
router.get('/sport', checkLoginStatus.admin, function(req, res, next) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ block content
|
||||||
label Ending year
|
label Ending year
|
||||||
span(class='form-section-input')
|
span(class='form-section-input')
|
||||||
input#season-textbox(type="number", name="year", value=currentYear)
|
input#season-textbox(type="number", name="year", value=currentYear)
|
||||||
|
.error #{message}
|
||||||
span(class='form-section')
|
span(class='form-section')
|
||||||
button#submit-button(type="submit" disabled) Submit
|
button#submit-button(type="submit" disabled) Submit
|
||||||
|
|
||||||
|
|
Reference in New Issue