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

Added User.getClasses

This commit is contained in:
2022-02-25 15:52:33 +00:00
parent f6efa74a89
commit 73bf0f699c

View File

@@ -4,6 +4,8 @@ const bcrypt = require('bcrypt');
const crypto = require('crypto');
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
const Class = require('./Class');
const PasswordReset = require('./PasswordReset');
const Test = require('./Test');
@@ -157,6 +159,32 @@ class User {
return await Promise.all(testObjects);
}
async getClasses() {
if (this.type === 'parent')
throw new Error(`Can not fetch class for ${this.type}`);
let sql = `
select
c.classId as classId
from
class c
join ${this.type}ClassLink link using(classId)
where
link.${this.type}Id = ?
order by
c.name;
`;
const conn = await new DatabaseConnectionPool();
const classes = await conn.runQuery(sql, [ this.id ]);
const classObjects = classes.map(c => {
return new Class(c.classId);
});
return await Promise.all(classObjects);
}
static async hashPassword(password) {
return await bcrypt.hash(password, 10);
}