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

Generalise getTeacher to getUser

This commit is contained in:
2022-03-03 01:57:49 +00:00
parent 6879622bea
commit 63e6fde021

View File

@@ -87,7 +87,7 @@ class Class {
this.teacherIds = ids.map(record => record.id);
const [ teachers, subject ] = await Promise.all([
this.getTeachers(),
this.getUsers(this.teacherIds, 'account'),
this.getSubject()
]);
@@ -102,12 +102,20 @@ class Class {
return new (require('./Subject'))(this.subjectId);
}
async getTeachers() {
const teacherPromises = this.teacherIds.map(id => {
return new (require('./Account'))(id);
async getUsers(ids, type) {
const types = {
account: 'Account',
student: 'Student'
};
if (!(type in types))
throw new Error('Invalid type');
const promises = ids.map(id => {
return new (require(`./${types[type]}`))(id);
});
return Promise.all(teacherPromises);
return Promise.all(promises);
}
async getTests({ order='desc', range='all' } = {}) {