Improve error handling for teams
parent
63b6ef2c2d
commit
6c174f3e02
|
@ -151,19 +151,25 @@ router.post('/division', checkLoginStatus.admin, async function(req, res, next)
|
|||
router.get('/team', checkLoginStatus.admin, function(req, res, next) {
|
||||
let title = req.query.team ? 'Edit Team' : 'Add Team'
|
||||
|
||||
res.render('manage/addteam', { title, userLoggedIn: !!req.user });
|
||||
res.render('manage/addteam', { title, userLoggedIn: !!req.user, message: req.flash('error') });
|
||||
});
|
||||
|
||||
router.post('/team', checkLoginStatus.admin, function(req, res, next) {
|
||||
const name = req.body['name'];
|
||||
const sport = req.body['sport'];
|
||||
|
||||
router.post('/team', checkLoginStatus.admin, async function(req, res, next) {
|
||||
const id = req.body['team'];
|
||||
const remove = req.body['remove'];
|
||||
|
||||
if(remove) teams.remove(id).then(res.redirect('/manage'));
|
||||
else if(id) teams.rename(id, name).then(res.redirect('/manage'));
|
||||
else teams.add(name, sport).then(res.redirect("/manage"));
|
||||
try {
|
||||
const name = req.body['name'];
|
||||
const sport = req.body['sport'];
|
||||
|
||||
if(remove) teams.remove(id).then(res.redirect('/manage'));
|
||||
else if(id) teams.rename(id, name).then(res.redirect('/manage'));
|
||||
else teams.add(name, sport).then(res.redirect("/manage"));
|
||||
} catch(err) {
|
||||
console.error("ERROR: " + err.message);
|
||||
req.flash("error", "An error has occurred.");
|
||||
res.redirect('/manage/team' + (id ? `?team=${id}` : ''));
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/account', checkLoginStatus.user, (req, res, next) => {
|
||||
|
|
|
@ -14,6 +14,7 @@ block content
|
|||
label Team name
|
||||
span(class='form-section-input')
|
||||
input#name-textbox(type="text", name="name" disabled)
|
||||
.error #{message}
|
||||
span(class='form-section')
|
||||
button#submit-button(type="submit" disabled) Submit
|
||||
span(class='form-section')
|
||||
|
|
Reference in New Issue