Skip to content

Build your personal knowledge base with Trilium Notes

server-ts: Fix "Missing or incorrect type for target branch ID"

Elian Doran4ab6f159e5e7
diff --git a/src/routes/api/notes.ts b/src/routes/api/notes.ts
index ec50c848a7..c5e3e1c37a 100644
--- a/src/routes/api/notes.ts
+++ b/src/routes/api/notes.ts
@@ -43,7 +43,7 @@ function createNote(req: Request) {
throw new ValidationError("Invalid target type.");
}
- if (typeof targetBranchId !== "string") {
+ if (targetBranchId && typeof targetBranchId !== "string") {
throw new ValidationError("Missing or incorrect type for target branch ID.");
}
diff --git a/src/services/notes.ts b/src/services/notes.ts
index 6dd68dc73e..a60799e80e 100644
--- a/src/services/notes.ts
+++ b/src/services/notes.ts
@@ -251,7 +251,7 @@ function createNewNote(params: NoteParams): {
});
}
-function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: string, params: NoteParams) {
+function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: string | undefined, params: NoteParams) {
if (!params.type) {
const parentNote = becca.notes[params.parentNoteId];
@@ -263,7 +263,7 @@ function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: str
if (target === 'into') {
return createNewNote(params);
}
- else if (target === 'after') {
+ else if (target === 'after' && targetBranchId) {
const afterBranch = becca.branches[targetBranchId];
// not updating utcDateModified to avoid having to sync whole rows