diff --git a/src/becca/entities/attribute.js b/src/becca/entities/attribute.js index d71ada463..d276afc18 100644 --- a/src/becca/entities/attribute.js +++ b/src/becca/entities/attribute.js @@ -113,7 +113,13 @@ class Attribute extends AbstractEntity { * @returns {Note|null} */ getNote() { - return this.becca.getNote(this.noteId); + const note = this.becca.getNote(this.noteId); + + if (!note) { + throw new Error(`Note '${this.noteId}' of attribute '${this.attributeId}', type '${this.type}', name '${this.name}' does not exist.`); + } + + return note; } /** diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.js index e3c366cbf..610f95e70 100644 --- a/src/becca/entities/branch.js +++ b/src/becca/entities/branch.js @@ -187,9 +187,7 @@ class Branch extends AbstractEntity { log.info("Deleting note " + note.noteId); - // marking note as deleted as a signal to event handlers that the note is being deleted - // (isDeleted is being checked against becca) - delete this.becca.notes[note.noteId]; + this.becca.notes[note.noteId].isBeingDeleted = true; for (const attribute of note.getOwnedAttributes()) { attribute.markAsDeleted(deleteId); diff --git a/src/becca/entities/note.js b/src/becca/entities/note.js index 4742977d9..94a212f2b 100644 --- a/src/becca/entities/note.js +++ b/src/becca/entities/note.js @@ -72,6 +72,8 @@ class Note extends AbstractEntity { this.utcDateCreated = utcDateCreated || dateUtils.utcNowDateTime(); /** @type {string} */ this.utcDateModified = utcDateModified; + /** @type {boolean} - set during the deletion operation, before it is completed (removed from becca completely) */ + this.isBeingDeleted = false; // ------ Derived attributes ------ @@ -1327,7 +1329,7 @@ class Note extends AbstractEntity { } get isDeleted() { - return !(this.noteId in this.becca.notes); + return !(this.noteId in this.becca.notes) || this.isBeingDeleted; } /**