Add better error management for seasons

main
sudoer777 2021-11-26 16:34:26 -07:00
parent f9ac3f49cd
commit 51783c5dec
2 changed files with 16 additions and 7 deletions

View File

@ -68,17 +68,25 @@ router.post('/game', checkLoginStatus.user, async 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) {
const year = req.body['year'];
router.post('/season', checkLoginStatus.admin, async function(req, res, next) {
try {
const year = req.body['year'];
const seasonID = req.body['season'];
const remove = req.body['remove'];
const seasonID = req.body['season'];
const remove = req.body['remove'];
if(remove) seasons.remove(seasonID).then(res.redirect('/manage'));
else seasons.add(year).then(res.redirect("/manage"));
if(remove) await seasons.remove(seasonID);
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) {

View File

@ -10,6 +10,7 @@ block content
label Ending year
span(class='form-section-input')
input#season-textbox(type="number", name="year", value=currentYear)
.error #{message}
span(class='form-section')
button#submit-button(type="submit" disabled) Submit