1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:39:28 +00:00

Add Class.addUser and scaffolding for Class.removeUser

This commit is contained in:
2022-03-29 10:10:46 +00:00
parent 3568762778
commit 3cb5929ea3

View File

@@ -206,12 +206,40 @@ class Class {
}).length; }).length;
} }
addTeacher() { async addUser(u) {
const validTypes = [ 'account', 'student' ];
if (!validTypes.includes(u.type))
throw new Error('Invalid user type');
const sql = `
insert into ${u.type}ClassLink(
${u.type}Id,
classId)
values
(?, ?);
`;
try {
await this.#conn.runQuery(sql, [
u.id,
this.id
]);
} catch (e) {
console.error(e);
throw new Error('Could not add user to class');
}
} }
removeTeacher() { removeUser(u) {
switch (u.type) {
case 'account':
break;
case 'student':
break;
default:
throw new Error('Invalid user type');
}
} }
calculateAverageMovement() { calculateAverageMovement() {