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:
23
lib/User.js
23
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user