lp1940105 Archive Course Should Use detach_material
authorKyle Huckins <khuckins@catalyte.io>
Sun, 27 Feb 2022 01:33:29 +0000 (01:33 +0000)
committerMichele Morgan <mmorgan@noblenet.org>
Tue, 18 Oct 2022 20:51:17 +0000 (16:51 -0400)
- Replaced resetItemFields with detachMaterials in Course Service
- Refactored disassociateMaterials to utilize detach_materials
- Refacotred deleteSelectedMaterials to utilize Course Service detachMaterials function

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts
Open-ILS/src/eg2/src/app/staff/share/course.service.ts

index 99fd469..8534d21 100644 (file)
@@ -204,12 +204,7 @@ export class CourseAssociateMaterialComponent extends DialogComponent implements
     }
 
     deleteSelectedMaterials(items) {
-        const deleteRequest$ = [];
-        items.forEach(item => {
-            deleteRequest$.push(this.net.request(
-                'open-ils.courses', 'open-ils.courses.detach_material',
-                this.auth.token(), item.id()));
-        });
+        let deleteRequest$ = this.course.detachMaterials(items);
         merge(...deleteRequest$).subscribe(
             val => {
                 this.materialDeleteSuccessString.current().then(str => this.toast.success(str));
index cb6e954..5376638 100644 (file)
@@ -157,6 +157,8 @@ export class CourseService {
     }
 
     disassociateMaterials(courses) {
+        const deleteRequest$ = [];
+
         return new Promise((resolve, reject) => {
             const course_ids = [];
             const course_library_hash = {};
@@ -164,23 +166,36 @@ export class CourseService {
                 course_ids.push(course.id());
                 course_library_hash[course.id()] = course.owning_lib();
             });
-            this.pcrud.search('acmcm', {course: course_ids}).subscribe(material => {
-                material.isdeleted(true);
-                this.resetItemFields(material, course_library_hash[material.course()]);
-                this.pcrud.autoApply(material).subscribe(() => {
+
+            this.pcrud.retrieveAll('acmcm', {course: course_ids}).subscribe(material => {
+                deleteRequest$.push(this.net.request(
+                  'open-ils.courses', 'open-ils.courses.detach_material',
+                  this.auth.token(), material.id()));
+            }, err => {
+                reject(err);
+            }, () => {
+                merge(...deleteRequest$).subscribe(val => {
+                    console.log(val);
                 }, err => {
                     reject(err);
                 }, () => {
-                    resolve(material);
+                    resolve(courses);
                 });
-            }, err => {
-                reject(err);
-            }, () => {
-                resolve(courses);
             });
         });
     }
 
+    detachMaterials(materials) {
+        const deleteRequest$ = [];
+        materials.forEach(material => {
+            deleteRequest$.push(this.net.request(
+                'open-ils.courses', 'open-ils.courses.detach_material',
+                this.auth.token(), material.id()));
+        });
+
+        return deleteRequest$;
+    }
+
     disassociateUsers(user) {
         return new Promise((resolve, reject) => {
             const user_ids = [];
@@ -206,28 +221,6 @@ export class CourseService {
         });
     }
 
-    resetItemFields(material, course_lib) {
-        this.pcrud.retrieve('acp', material.item(),
-            {flesh: 3, flesh_fields: {acp: ['call_number']}}).subscribe(copy => {
-            if (material.original_status()) {
-                copy.status(material.original_status());
-            }
-            if (copy.circ_modifier() !== material.original_circ_modifier()) {
-                copy.circ_modifier(material.original_circ_modifier());
-            }
-            if (material.original_location()) {
-                copy.location(material.original_location());
-            }
-            if (material.original_callnumber()) {
-                this.pcrud.retrieve('acn', material.original_callnumber()).subscribe(cn => {
-                    this.updateItem(copy, course_lib, cn.label(), true);
-                });
-            } else {
-                this.updateItem(copy, course_lib, copy.call_number().label(), false);
-            }
-        });
-    }
-
 
     updateItem(item: IdlObject, courseLib: IdlObject, callNumber: string, updatingVolume: boolean) {
         const cn = item.call_number();