From: Jane Sandberg Date: Fri, 11 Sep 2020 19:49:10 +0000 (-0700) Subject: LP1849212: don't send empty courseId arrays to pcrud X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b0473a58b55de3599b7739aa9e212462b3f7862d;p=evergreen%2Fpines.git LP1849212: don't send empty courseId arrays to pcrud Also removes some unneeded Import calls Signed-off-by: Jane Sandberg Signed-off-by: Michele Morgan Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts index 9f0f266735..bd066a72e0 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts @@ -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; + } }); } }); diff --git a/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts b/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts index ec3ba57878..3a09fd83d5 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts @@ -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; + } }); } }); diff --git a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts index 43caf76528..4cca3efe48 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -87,14 +87,17 @@ export class CourseService { } fetchCoursesForRecord(recordId) { - const courseIds = []; - return this.pcrud.search( + const courseIds = new Set(); + 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