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) {
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Reference in New Issue