1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 19:59:27 +00:00

Fully implemented Class.removeUser

This commit is contained in:
2022-03-31 08:50:09 +00:00
parent 9fb499bbe5
commit dc95b64480

View File

@@ -231,14 +231,27 @@ class Class {
}
}
removeUser(u) {
switch (u.type) {
case 'account':
break;
case 'student':
break;
default:
throw new Error('Invalid user type');
async removeUser(u) {
const validTypes = [ 'account', 'student' ];
if (!validTypes.includes(u.type))
throw new Error('Invalid user type');
const sql = `
delete from ${u.type}ClassLink
where
${u.type}id = ?
and classId = ?;
`;
try {
await this.#conn.runQuery(sql, [
u.id,
this.id
]);
} catch (e) {
console.error(e);
throw new Error('Could not remove user from class');
}
}