From a24658ac0eea4b5cafb3d34d86ca593202958a89 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 25 Sep 2023 10:43:54 +0500 Subject: [PATCH] core: fix "Cannot read property type of undefined" --- packages/core/src/collections/notebooks.js | 6 +++++- packages/core/src/collections/notes.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/collections/notebooks.js b/packages/core/src/collections/notebooks.js index b64ed3146..18a61fe9b 100644 --- a/packages/core/src/collections/notebooks.js +++ b/packages/core/src/collections/notebooks.js @@ -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); } diff --git a/packages/core/src/collections/notes.js b/packages/core/src/collections/notes.js index 06569b775..be132a76f 100644 --- a/packages/core/src/collections/notes.js +++ b/packages/core/src/collections/notes.js @@ -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); }