diff --git a/lib/User.js b/lib/User.js index f723e72..3095786 100644 --- a/lib/User.js +++ b/lib/User.js @@ -111,7 +111,28 @@ class User { return res; } - static getUserByEmail() { + static async getUserByEmail(email) { + const conn = await new DatabaseConnectionPool(); + const types = [ 'account', 'student', 'parent' ]; + + for (const type of types) { + const sql = ` + select ${type}id as id + from ${type} + where email = ?; + `; + + const id = (await conn.runQuery(sql, [ + email + ]))?.[0]?.['id']; + + if (typeof id !== 'undefined') { + const className = + `${type.substring(0, 1).toUpperCase()}` + + `${type.substring(1)}`; + return new (require(`./${className}`))(id); + } + } } }