(ownerId, options = {})
| 65 | }, |
| 66 | |
| 67 | async fetchByOwner (ownerId, options = {}) { |
| 68 | let projectionString = '' |
| 69 | if (Array.isArray(options.project)) { |
| 70 | projectionString += `&project=${options.project.join(',')}` |
| 71 | } |
| 72 | if (options.includeShared) { |
| 73 | projectionString += '&includeShared=true' |
| 74 | } |
| 75 | const classrooms = await fetchJson(`/db/classroom?ownerID=${ownerId}${projectionString}`, { |
| 76 | callOz: options.callOz, |
| 77 | method: 'GET' |
| 78 | }) |
| 79 | |
| 80 | if (classrooms.length > 0) { |
| 81 | const classroomLanguages = [...classrooms.reduce((acc, classroom) => { |
| 82 | acc.add(classroom.aceConfig.language) |
| 83 | return acc |
| 84 | }, new Set())] |
| 85 | |
| 86 | const coursesByLanguagePromises = classroomLanguages.map(lang => |
| 87 | fetchJson(`/db/classroom-courses-data?language=${lang}`) |
| 88 | .then(courses => ({ [lang]: courses })) |
| 89 | ) |
| 90 | |
| 91 | const coursesResults = await Promise.all(coursesByLanguagePromises) |
| 92 | const coursesByLanguage = Object.assign({}, ...coursesResults) |
| 93 | |
| 94 | classrooms.forEach(classroom => { |
| 95 | classroom.courses = coursesByLanguage[classroom.aceConfig.language] |
| 96 | }) |
| 97 | } |
| 98 | |
| 99 | return classrooms |
| 100 | }, |
| 101 | |
| 102 | fetchByCourseInstanceId (courseInstanceId) { |
| 103 | return fetchJson(`/db/classroom?courseInstanceId=${courseInstanceId}`, { |
nothing calls this directly
no outgoing calls
no test coverage detected