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

Class should fetch class members too

This commit is contained in:
2022-03-03 01:58:26 +00:00
parent 63e6fde021
commit dd5778e872

View File

@@ -40,6 +40,18 @@ class Class {
*/
teachers;
/**
* The ids of the students assigned to the class
* @type {Array<string>}
*/
studentIds;
/**
* The students assigned to the class
* @type {Array<Account>}
*/
students;
/**
* @param {string} classID - The id of the class to fetch
*/
@@ -55,7 +67,7 @@ class Class {
classId = ?;
`;
const teacherIdSQL = `
const teacherSQL = `
select
a.accountId as id
from
@@ -66,8 +78,20 @@ class Class {
`;
const studentSQL = `
select
s.studentId as id
from
student s
join studentClassLink scl using (studentId)
where
scl.classId = ?;
`;
return (async () => {
const conn = await new DatabaseConnectionPool();
const record = await conn.runQuery(sql, [
classId
]);
@@ -78,20 +102,32 @@ class Class {
for (const [ k, v ] of Object.entries(record[0]))
this[k] = v;
const ids = await conn.runQuery(teacherIdSQL, [
classId
const [ teacherRes, studentRes ] = await Promise.all([
conn.runQuery(teacherSQL, [
classId
]),
conn.runQuery(studentSQL, [
classId
])
]);
conn.close();
this.teacherIds = ids.map(record => record.id);
this.teacherIds = teacherRes.map(record => record.id);
this.studentIds = studentRes.map(record => record.id);
const [ teachers, subject ] = await Promise.all([
const [
teachers,
students,
subject,
] = await Promise.all([
this.getUsers(this.teacherIds, 'account'),
this.getUsers(this.studentIds, 'student'),
this.getSubject()
]);
this.teachers = teachers;
this.students = students;
this.subject = subject;
return this;
@@ -159,10 +195,6 @@ class Class {
return await Promise.all(testObjects);
}
get students() {
}
addTeacher() {
}