1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:19:26 +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; 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 * @param {string} classID - The id of the class to fetch
*/ */
@@ -55,7 +67,7 @@ class Class {
classId = ?; classId = ?;
`; `;
const teacherIdSQL = ` const teacherSQL = `
select select
a.accountId as id a.accountId as id
from 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 () => { return (async () => {
const conn = await new DatabaseConnectionPool(); const conn = await new DatabaseConnectionPool();
const record = await conn.runQuery(sql, [ const record = await conn.runQuery(sql, [
classId classId
]); ]);
@@ -78,20 +102,32 @@ class Class {
for (const [ k, v ] of Object.entries(record[0])) for (const [ k, v ] of Object.entries(record[0]))
this[k] = v; this[k] = v;
const ids = await conn.runQuery(teacherIdSQL, [ const [ teacherRes, studentRes ] = await Promise.all([
classId conn.runQuery(teacherSQL, [
classId
]),
conn.runQuery(studentSQL, [
classId
])
]); ]);
conn.close(); 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.teacherIds, 'account'),
this.getUsers(this.studentIds, 'student'),
this.getSubject() this.getSubject()
]); ]);
this.teachers = teachers; this.teachers = teachers;
this.students = students;
this.subject = subject; this.subject = subject;
return this; return this;
@@ -159,10 +195,6 @@ class Class {
return await Promise.all(testObjects); return await Promise.all(testObjects);
} }
get students() {
}
addTeacher() { addTeacher() {
} }