LP1849212: don't send empty courseId arrays to pcrud
authorJane Sandberg <sandbej@linnbenton.edu>
Fri, 11 Sep 2020 19:49:10 +0000 (12:49 -0700)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 14 Sep 2020 22:17:48 +0000 (18:17 -0400)
Also removes some unneeded Import calls

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts
Open-ILS/src/eg2/src/app/staff/share/course.service.ts

index 9f0f266..bd066a7 100644 (file)
@@ -1,11 +1,10 @@
 import {Component, OnInit, OnDestroy, Input} from '@angular/core';
 import {Subscription} from 'rxjs';
-import {Router, ParamMap} from '@angular/router';
+import {Router} from '@angular/router';
 import {OrgService} from '@eg/core/org.service';
-import {NetService} from '@eg/core/net.service';
 import {IdlObject} from '@eg/core/idl.service';
 import {CatalogService} from '@eg/share/catalog/catalog.service';
-import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
+import {BibRecordSummary} from '@eg/share/catalog/bib-record.service';
 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
 import {StaffCatalogService} from '../catalog.service';
@@ -36,8 +35,6 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
     constructor(
         private router: Router,
         private org: OrgService,
-        private net: NetService,
-        private bib: BibRecordService,
         private cat: CatalogService,
         private catUrl: CatalogUrlService,
         private staffCat: StaffCatalogService,
@@ -64,10 +61,12 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
         this.course.isOptedIn().then(res => {
             if (res) {
                 this.course.fetchCoursesForRecord(recordId).then(course_list => {
-                    Object.keys(course_list).forEach(key => {
-                        this.courses.push(course_list[key]);
-                    });
-                    this.hasCourse = true;
+                    if (course_list) {
+                        Object.keys(course_list).forEach(key => {
+                            this.courses.push(course_list[key]);
+                        });
+                        this.hasCourse = true;
+                    }
                 });
             }
         });
index ec3ba57..3a09fd8 100644 (file)
@@ -81,8 +81,10 @@ export class BibSummaryComponent implements OnInit {
         this.org.settings('circ.course_materials_opt_in').then(setting => {
             if (setting['circ.course_materials_opt_in']) {
                 this.course.fetchCoursesForRecord(recordId).then(courseList => {
-                    this.courses = courseList;
-                    this.hasCourse = true;
+                    if (courseList) {
+                        this.courses = courseList;
+                        this.hasCourse = true;
+                    }
                 });
             }
         });
index 43caf76..4cca3ef 100644 (file)
@@ -87,14 +87,17 @@ export class CourseService {
     }
 
     fetchCoursesForRecord(recordId) {
-        const courseIds = [];
-                 return this.pcrud.search(
+        const courseIds = new Set<number>();
+        return this.pcrud.search(
             'acmcm', {record: recordId}, {atomic: false}
         ).pipe(tap(material => {
-            if (courseIds.indexOf(material.course()) === -1) {
-                courseIds.push(material.course());
+            courseIds.add(material.course());
+        })).toPromise()
+        .then(() => {
+            if (courseIds.size) {
+                return this.getCourses(Array.from(courseIds));
             }
-        })).toPromise().then(() => this.getCourses(courseIds));
+        });
     }
 
     // Creating a new acmcm Entry