MOBILE-2428 courses: Fix error reading from DB if no courses
parent
c17534d69d
commit
0b6972cbd3
|
@ -96,17 +96,20 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
|
||||||
|
|
||||||
this.courseIds = courseIds.join(',');
|
this.courseIds = courseIds.join(',');
|
||||||
|
|
||||||
// Load course image of all the courses.
|
if (this.courseIds) {
|
||||||
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
// Load course image of all the courses.
|
||||||
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
||||||
courses.forEach((course) => {
|
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
||||||
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles && coursesInfo[course.id].overviewfiles[0]) {
|
courses.forEach((course) => {
|
||||||
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles &&
|
||||||
} else {
|
coursesInfo[course.id].overviewfiles[0]) {
|
||||||
course.imageThumb = false;
|
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
||||||
}
|
} else {
|
||||||
});
|
course.imageThumb = false;
|
||||||
}));
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
courses.forEach((course) => {
|
courses.forEach((course) => {
|
||||||
|
@ -137,7 +140,9 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
|
||||||
|
|
||||||
promises.push(this.coursesProvider.invalidateUserCourses());
|
promises.push(this.coursesProvider.invalidateUserCourses());
|
||||||
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
|
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
|
||||||
promises.push(this.coursesProvider.invalidateCoursesByField('ids', this.courseIds));
|
if (this.courseIds) {
|
||||||
|
promises.push(this.coursesProvider.invalidateCoursesByField('ids', this.courseIds));
|
||||||
|
}
|
||||||
|
|
||||||
Promise.all(promises).finally(() => {
|
Promise.all(promises).finally(() => {
|
||||||
|
|
||||||
|
|
|
@ -217,17 +217,20 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
||||||
|
|
||||||
this.courseIds = courseIds.join(',');
|
this.courseIds = courseIds.join(',');
|
||||||
|
|
||||||
// Load course image of all the courses.
|
if (this.courseIds) {
|
||||||
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
// Load course image of all the courses.
|
||||||
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
||||||
courses.forEach((course) => {
|
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
||||||
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles && coursesInfo[course.id].overviewfiles[0]) {
|
courses.forEach((course) => {
|
||||||
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles &&
|
||||||
} else {
|
coursesInfo[course.id].overviewfiles[0]) {
|
||||||
course.imageThumb = false;
|
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
||||||
}
|
} else {
|
||||||
});
|
course.imageThumb = false;
|
||||||
}));
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return Promise.all(promises).then(() => {
|
||||||
return courses.sort((a, b) => {
|
return courses.sort((a, b) => {
|
||||||
|
@ -286,7 +289,9 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
||||||
|
|
||||||
promises.push(this.coursesProvider.invalidateUserCourses());
|
promises.push(this.coursesProvider.invalidateUserCourses());
|
||||||
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
|
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
|
||||||
promises.push(this.coursesProvider.invalidateCoursesByField('ids', this.courseIds));
|
if (this.courseIds) {
|
||||||
|
promises.push(this.coursesProvider.invalidateCoursesByField('ids', this.courseIds));
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(promises).finally(() => {
|
return Promise.all(promises).finally(() => {
|
||||||
switch (this.tabShown) {
|
switch (this.tabShown) {
|
||||||
|
|
Loading…
Reference in New Issue