MOBILE-3245 grades: Fix network methods calls when populating grades
parent
5337c77b7e
commit
accb83b339
|
@ -200,15 +200,22 @@ export class CoreGradesHelperProvider {
|
||||||
*/
|
*/
|
||||||
async getGradesCourseData(grades: any[]): Promise<any> {
|
async getGradesCourseData(grades: any[]): Promise<any> {
|
||||||
// Obtain courses from cache to prevent network requests.
|
// Obtain courses from cache to prevent network requests.
|
||||||
const courses = await this.coursesProvider.getUserCourses(undefined, undefined, ReadingStrategy.OnlyCache);
|
let coursesWereMissing;
|
||||||
|
|
||||||
const coursesMap = this.utils.arrayToObject(courses, 'id');
|
try {
|
||||||
const coursesWereMissing = this.addCourseData(grades, coursesMap);
|
const courses = await this.coursesProvider.getUserCourses(undefined, undefined, ReadingStrategy.OnlyCache);
|
||||||
|
|
||||||
|
const coursesMap = this.utils.arrayToObject(courses, 'id');
|
||||||
|
|
||||||
|
coursesWereMissing = this.addCourseData(grades, coursesMap);
|
||||||
|
} catch (error) {
|
||||||
|
coursesWereMissing = true;
|
||||||
|
}
|
||||||
|
|
||||||
// If any course wasn't found, make a network request.
|
// If any course wasn't found, make a network request.
|
||||||
if (coursesWereMissing) {
|
if (coursesWereMissing) {
|
||||||
const coursesPromise = this.coursesProvider.isGetCoursesByFieldAvailable()
|
const coursesPromise = this.coursesProvider.isGetCoursesByFieldAvailable()
|
||||||
? this.coursesProvider.getCoursesByField('ids', grades.map((grade) => grade.courseid))
|
? this.coursesProvider.getCoursesByField('ids', grades.map((grade) => grade.courseid).join(','))
|
||||||
: this.coursesProvider.getUserCourses(undefined, undefined, ReadingStrategy.PreferNetwork);
|
: this.coursesProvider.getUserCourses(undefined, undefined, ReadingStrategy.PreferNetwork);
|
||||||
|
|
||||||
const courses = await coursesPromise;
|
const courses = await coursesPromise;
|
||||||
|
|
Loading…
Reference in New Issue