diff --git a/lib/Class.js b/lib/Class.js index 076f21a..e464bf2 100644 --- a/lib/Class.js +++ b/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' } = {}) {