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

Implemented Account.getUserByEmail

This commit is contained in:
2022-02-13 22:17:38 +00:00
parent 2f00e30ca6
commit 8e91966d4b

View File

@@ -111,7 +111,28 @@ class User {
return res; 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);
}
}
} }
} }