From c9daea6d48f3aeda3ad3dcfc49c136a3ea5ef07e Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sat, 7 Oct 2023 14:02:18 +0500 Subject: [PATCH] core: fix monographs --- packages/core/__e2e__/monographs.test.js | 16 +++++++++++----- packages/core/src/api/monographs.ts | 15 ++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/core/__e2e__/monographs.test.js b/packages/core/__e2e__/monographs.test.js index d59373526..5486abba6 100644 --- a/packages/core/__e2e__/monographs.test.js +++ b/packages/core/__e2e__/monographs.test.js @@ -53,10 +53,12 @@ test( const monographId = await db.monographs.publish(id); - expect(db.monographs.all.find((m) => m.id === id)).toBeDefined(); + expect( + (await db.monographs.all()).find((m) => m.id === id) + ).toBeDefined(); const monograph = await db.monographs.get(monographId); - const note = db.notes.note(id); + const note = await db.notes.note(id); expect(monograph.id).toBe(monographId); expect(monograph.title).toBe(note.title); @@ -74,7 +76,7 @@ test( const monographId = await db.monographs.publish(id); let monograph = await db.monographs.get(monographId); - const note = db.notes.note(id); + const note = await db.notes.note(id); expect(monograph.title).toBe(note.title); const editedTitle = "EDITED TITLE OF MY NOTE!"; @@ -96,10 +98,14 @@ test( await db.monographs.refresh(); await db.monographs.publish(id); - expect(db.monographs.all.find((m) => m.id === id)).toBeDefined(); + expect( + (await db.monographs.all()).find((m) => m.id === id) + ).toBeDefined(); await db.monographs.unpublish(id); - expect(db.monographs.all.find((m) => m.id === id)).toBeUndefined(); + expect( + (await db.monographs.all()).find((m) => m.id === id) + ).toBeUndefined(); await logout(db); }), diff --git a/packages/core/src/api/monographs.ts b/packages/core/src/api/monographs.ts index d7727beb3..988591639 100644 --- a/packages/core/src/api/monographs.ts +++ b/packages/core/src/api/monographs.ts @@ -20,7 +20,7 @@ along with this program. If not, see . import http from "../utils/http"; import Constants from "../utils/constants"; import Database from "."; -import { Note, isDeleted } from "../types"; +import { isDeleted } from "../types"; import { isUnencryptedContent } from "../collections/content"; import { Cipher } from "@notesnook/crypto"; @@ -93,11 +93,11 @@ export class Monographs { const token = await this.db.tokenManager.getAccessToken(); if (!user || !token) throw new Error("Please login to publish a note."); - const note = this.db.notes.note(noteId); + const note = await this.db.notes.note(noteId); if (!note) throw new Error("No such note found."); - if (!note.data.contentId) throw new Error("Cannot publish an empty note."); + if (!note.contentId) throw new Error("Cannot publish an empty note."); - const contentItem = await this.db.content.raw(note.data.contentId); + const contentItem = await this.db.content.get(note.contentId); if (!contentItem || isDeleted(contentItem)) throw new Error("Could not find content for this note."); @@ -163,12 +163,9 @@ export class Monographs { this.monographs.splice(this.monographs.indexOf(noteId), 1); } - get all() { + async all() { if (!this.monographs.length) return []; - - return this.monographs - .map((noteId) => this.db.notes.note(noteId)?.data) - .filter(Boolean) as Note[]; + return await this.db.notes.all.items(this.monographs); } get(monographId: string) {