mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:39:28 +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);
|
this.teacherIds = ids.map(record => record.id);
|
||||||
|
|
||||||
const [ teachers, subject ] = await Promise.all([
|
const [ teachers, subject ] = await Promise.all([
|
||||||
this.getTeachers(),
|
this.getUsers(this.teacherIds, 'account'),
|
||||||
this.getSubject()
|
this.getSubject()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -102,12 +102,20 @@ class Class {
|
|||||||
return new (require('./Subject'))(this.subjectId);
|
return new (require('./Subject'))(this.subjectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeachers() {
|
async getUsers(ids, type) {
|
||||||
const teacherPromises = this.teacherIds.map(id => {
|
const types = {
|
||||||
return new (require('./Account'))(id);
|
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' } = {}) {
|
async getTests({ order='desc', range='all' } = {}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user