mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 17:59:25 +00:00
Generalise getTeacher to getUser
This commit is contained in:
18
lib/Class.js
18
lib/Class.js
@@ -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' } = {}) {
|
||||
|
||||
Reference in New Issue
Block a user