From dc95b64480ffc6da687c185408a0c31e3c61bb04 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 31 Mar 2022 08:50:09 +0000 Subject: [PATCH] Fully implemented Class.removeUser --- lib/Class.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/Class.js b/lib/Class.js index c18719e..0a94c13 100644 --- a/lib/Class.js +++ b/lib/Class.js @@ -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'); } }