diff --git a/src/routes/api/notes.ts b/src/routes/api/notes.ts index ec50c848a..c5e3e1c37 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 6dd68dc73..a60799e80 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