mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-02 01:19:31 +00:00
Should not allow teachers to remove the last teacher from class
This commit is contained in:
@@ -244,6 +244,11 @@ class Class {
|
|||||||
if (!validTypes.includes(u.type))
|
if (!validTypes.includes(u.type))
|
||||||
throw new Error('Invalid user type');
|
throw new Error('Invalid user type');
|
||||||
|
|
||||||
|
this.teachers = await this.getTeachers();
|
||||||
|
|
||||||
|
if (u.type === 'account' && this.teachers.length < 2)
|
||||||
|
throw new Error('Can\'t remove last teacher');
|
||||||
|
|
||||||
const sql = `
|
const sql = `
|
||||||
delete from ${u.type}ClassLink
|
delete from ${u.type}ClassLink
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -240,8 +240,18 @@ router.post('/:id/:userType(members|teachers)/:userId/remove',
|
|||||||
const u = await new User(req.db, null, req.params.userId);
|
const u = await new User(req.db, null, req.params.userId);
|
||||||
const userType = req.params.userType;
|
const userType = req.params.userType;
|
||||||
|
|
||||||
await c.removeUser(u);
|
try {
|
||||||
return res.redirect(`/admin/class/${c.id}/${userType}`);
|
await c.removeUser(u);
|
||||||
|
return res.redirect(`/admin/class/${c.id}/${userType}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return res.render('error', {
|
||||||
|
title: 'Stratos - Error',
|
||||||
|
current: 'Classes',
|
||||||
|
name: req.session.fullName,
|
||||||
|
msg: `Can not remove this user: ${e.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user