mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:39:28 +00:00
Add ability to extract teachers Accounts from Class
This commit is contained in:
48
lib/Class.js
48
lib/Class.js
@@ -27,6 +27,18 @@ class Class {
|
||||
*/
|
||||
name;
|
||||
|
||||
/**
|
||||
* The ids of the teachers assigned to the class
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
teacherIds;
|
||||
|
||||
/**
|
||||
* The teachers assigned to the class
|
||||
* @type {Array<Account>}
|
||||
*/
|
||||
teachers;
|
||||
|
||||
/**
|
||||
* @param {string} classID - The id of the class to fetch
|
||||
*/
|
||||
@@ -42,10 +54,21 @@ class Class {
|
||||
classId = ?;
|
||||
`;
|
||||
|
||||
const teacherIdSQL = `
|
||||
select
|
||||
a.accountId as id
|
||||
from
|
||||
account a
|
||||
join accountClassLink acl using (accountId)
|
||||
where
|
||||
acl.classId = ?;
|
||||
|
||||
`;
|
||||
|
||||
return (async () => {
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
const record = await conn.runQuery(sql, [
|
||||
classId,
|
||||
classId
|
||||
]);
|
||||
|
||||
if (!record.length)
|
||||
@@ -54,7 +77,19 @@ class Class {
|
||||
for (const [ k, v ] of Object.entries(record[0]))
|
||||
this[k] = v;
|
||||
|
||||
this.subject = await this.getSubject();
|
||||
const ids = await conn.runQuery(teacherIdSQL, [
|
||||
classId
|
||||
]);
|
||||
|
||||
this.teacherIds = ids.map(record => record.id);
|
||||
|
||||
const [ teachers, subject ] = await Promise.all([
|
||||
this.getTeachers(),
|
||||
this.getSubject()
|
||||
]);
|
||||
|
||||
this.teachers = teachers;
|
||||
this.subject = subject;
|
||||
|
||||
return this;
|
||||
})();
|
||||
@@ -64,17 +99,18 @@ class Class {
|
||||
return new (require('./Subject'))(this.subjectId);
|
||||
}
|
||||
|
||||
async getTeachers() {
|
||||
const teacherPromises = this.teacherIds.map(id => {
|
||||
return new (require('./Account'))(id);
|
||||
});
|
||||
|
||||
return Promise.all(teacherPromises);
|
||||
}
|
||||
|
||||
get tests() {
|
||||
|
||||
}
|
||||
|
||||
get teachers() {
|
||||
|
||||
}
|
||||
|
||||
get students() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user