mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: fix monographs
This commit is contained in:
committed by
Abdullah Atta
parent
84b786b5a3
commit
7cf8895b4d
@@ -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);
|
||||
}),
|
||||
|
||||
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user