LP1866546 MARC edit support authority record (un)delete
authorBill Erickson <berickxx@gmail.com>
Tue, 10 Mar 2020 14:48:27 +0000 (10:48 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Sat, 11 Jul 2020 02:47:24 +0000 (19:47 -0700)
Teaches the Angular MARC editor to use PCRUD for deleting and undeleting
authority records instead of erroneously using the bib record delete /
undelete APIs.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts

index 0bc308a..241379f 100644 (file)
@@ -291,50 +291,109 @@ export class MarcEditorComponent implements OnInit {
         .then(yes => {
             if (!yes) { return; }
 
-            return this.net.request('open-ils.cat',
-                'open-ils.cat.biblio.record_entry.delete',
-                this.auth.token(), this.record.id).toPromise()
-
-            .then(resp => {
-
-                const evt = this.evt.parse(resp);
-                if (evt) {
-                    if (evt.textcode === 'RECORD_NOT_EMPTY') {
-                        return this.cannotDelete.open().toPromise();
-                    } else {
-                        console.error(evt);
-                        return alert(evt);
-                    }
-                }
-                return this.fromId(this.record.id)
-                .then(_ => this.recordSaved.emit(
-                    {marcXml: this.record.toXml(), recordId: this.recordId}));
+            let promise;
+            if (this.recordType === 'authority') {
+                promise = this.deleteAuthorityRecord();
+            } else {
+                promise = this.deleteBibRecord();
+            }
+
+            return promise.then(ok => {
+                if (!ok) { return; }
+
+                return this.fromId(this.record.id).then(_ => {
+                    this.recordSaved.emit({
+                        marcXml: this.record.toXml(),
+                        recordId: this.recordId
+                    });
+                });
             });
         });
     }
 
+    deleteAuthorityRecord(): Promise<boolean> {
+        return this.pcrud.retrieve('are', this.record.id).toPromise()
+        .then(rec => this.pcrud.remove(rec).toPromise())
+        .then(resp => resp !== null);
+    }
+
+    deleteBibRecord(): Promise<boolean> {
+
+        return this.net.request('open-ils.cat',
+            'open-ils.cat.biblio.record_entry.delete',
+            this.auth.token(), this.record.id).toPromise()
+
+        .then(resp => {
+
+            const evt = this.evt.parse(resp);
+            if (evt) {
+                if (evt.textcode === 'RECORD_NOT_EMPTY') {
+                    return this.cannotDelete.open().toPromise()
+                    .then(_ => false);
+                } else {
+                    console.error(evt);
+                    alert(evt);
+                    return false;
+                }
+            }
+
+            return true;
+        });
+    }
+
     undeleteRecord(): Promise<any> {
 
         return this.confirmUndelete.open().toPromise()
         .then(yes => {
             if (!yes) { return; }
 
-            return this.net.request('open-ils.cat',
-                'open-ils.cat.biblio.record_entry.undelete',
-                this.auth.token(), this.record.id).toPromise()
-
-            .then(resp => {
-
-                const evt = this.evt.parse(resp);
-                if (evt) { console.error(evt); return alert(evt); }
+            let promise;
+            if (this.recordType === 'authority') {
+                promise = this.undeleteAuthorityRecord();
+            } else {
+                promise = this.undeleteBibRecord();
+            }
 
+            return promise.then(ok => {
+                if (!ok) { return; }
                 return this.fromId(this.record.id)
-                .then(_ => this.recordSaved.emit(
-                    {marcXml: this.record.toXml(), recordId: this.recordId}));
+                .then(_ => {
+                    this.recordSaved.emit({
+                        marcXml: this.record.toXml(),
+                        recordId: this.recordId
+                    });
+                });
             });
         });
     }
 
+    undeleteAuthorityRecord(): Promise<any> {
+        return this.pcrud.retrieve('are', this.record.id).toPromise()
+        .then(rec => {
+            rec.deleted('f');
+            return this.pcrud.update(rec).toPromise();
+        }).then(resp => resp !== null);
+    }
+
+    undeleteBibRecord(): Promise<any> {
+
+        return this.net.request('open-ils.cat',
+            'open-ils.cat.biblio.record_entry.undelete',
+            this.auth.token(), this.record.id).toPromise()
+
+        .then(resp => {
+
+            const evt = this.evt.parse(resp);
+            if (evt) {
+                console.error(evt);
+                alert(evt);
+                return false;
+            }
+
+            return true;
+        });
+    }
+
     // Spawns the copy editor with the requested barcode and
     // call number label.  Called after our record is saved.
     fastAdd() {