From: Bill Erickson Date: Tue, 10 Mar 2020 14:48:27 +0000 (-0400) Subject: LP1866546 MARC edit support authority record (un)delete X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b2ad08e21d52299ee08073fd5307c98e422830ef;p=evergreen%2Fpines.git LP1866546 MARC edit support authority record (un)delete 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 Signed-off-by: Jane Sandberg --- diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts index 0bc308a6cc..241379f382 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts @@ -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 { + return this.pcrud.retrieve('are', this.record.id).toPromise() + .then(rec => this.pcrud.remove(rec).toPromise()) + .then(resp => resp !== null); + } + + deleteBibRecord(): Promise { + + 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 { 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 { + 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 { + + 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() {