core: fix "Cannot read property type of undefined"

This commit is contained in:
Abdullah Atta
2023-09-25 10:43:54 +05:00
parent bb77385b66
commit a24658ac0e
2 changed files with 9 additions and 2 deletions

View File

@@ -143,7 +143,11 @@ export default class Notebooks extends Collection {
* @returns {Notebook} The notebook of the given id
*/
notebook(id) {
let notebook = id.type ? id : this._collection.getItem(id);
if (!id) return;
let notebook =
typeof id === "object" && "type" in id
? id
: this._collection.getItem(id);
if (!notebook || notebook.deleted) return;
return new Notebook(notebook, this._db);
}

View File

@@ -146,7 +146,10 @@ export default class Notes extends Collection {
*/
note(id) {
if (!id) return;
let note = id.type ? id : this._collection.getItem(id);
let note =
typeof id === "object" && "type" in id
? id
: this._collection.getItem(id);
if (!note || note.deleted) return;
return new Note(note, this._db);
}