mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 18:39:32 +00:00
Added User.getClasses
This commit is contained in:
28
lib/User.js
28
lib/User.js
@@ -4,6 +4,8 @@ const bcrypt = require('bcrypt');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||||
|
|
||||||
|
const Class = require('./Class');
|
||||||
const PasswordReset = require('./PasswordReset');
|
const PasswordReset = require('./PasswordReset');
|
||||||
const Test = require('./Test');
|
const Test = require('./Test');
|
||||||
|
|
||||||
@@ -157,6 +159,32 @@ class User {
|
|||||||
return await Promise.all(testObjects);
|
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) {
|
static async hashPassword(password) {
|
||||||
return await bcrypt.hash(password, 10);
|
return await bcrypt.hash(password, 10);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user