LP1821382 Conjoined linking repairs
authorBill Erickson <berickxx@gmail.com>
Tue, 26 Mar 2019 17:58:46 +0000 (13:58 -0400)
committerDan Wells <dbw2@calvin.edu>
Wed, 29 May 2019 19:30:50 +0000 (15:30 -0400)
Modify existing copy->record conjoined links where necessary instead of
create duplicates.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>

Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.ts

index 51000a7..69ff7e7 100644 (file)
@@ -30,6 +30,7 @@ export class ConjoinedItemsDialogComponent
     numFailed: number;
     peerTypes: ComboboxEntry[];
     peerRecord: number;
+    existingMaps: any;
 
     onOpenSub: Subscription;
 
@@ -64,6 +65,8 @@ export class ConjoinedItemsDialogComponent
             if (this.peerTypes.length === 0) {
                 this.getPeerTypes();
             }
+
+            this.fetchExisting();
         });
     }
 
@@ -71,6 +74,13 @@ export class ConjoinedItemsDialogComponent
         this.onOpenSub.unsubscribe();
     }
 
+    fetchExisting() {
+        this.existingMaps = {};
+        this.pcrud.search('bpbcm',
+            {target_copy: this.copyIds, peer_record: this.peerRecord})
+        .subscribe(map => this.existingMaps[map.target_copy()] = map);
+    }
+
     getPeerTypes(): Promise<any> {
         return this.pcrud.retrieveAll('bpt', {}, {atomic: true}).toPromise()
         .then(types =>
@@ -95,12 +105,19 @@ export class ConjoinedItemsDialogComponent
         }
 
         const id = this.ids.pop();
-        const map = this.idl.create('bpbcm');
+        const map = this.existingMaps[id] || this.idl.create('bpbcm');
         map.peer_record(this.peerRecord);
         map.target_copy(id);
         map.peer_type(this.peerType);
 
-        return this.pcrud.create(map).toPromise().then(
+        let promise: Promise<any>;
+        if (this.existingMaps[id]) {
+            promise = this.pcrud.update(map).toPromise();
+        } else {
+            promise = this.pcrud.create(map).toPromise();
+        }
+
+        return promise.then(
             ok => {
                 this.successMsg.current().then(msg => this.toast.success(msg));
                 this.numSucceeded++;