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

When attempting to add a new note from the relation map
This commit is contained in:
Elian Doran 2024-04-06 22:17:47 +03:00
parent b50ceaf299
commit 4ab6f159e5
No known key found for this signature in database
2 changed files with 3 additions and 3 deletions

View File

@ -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.");
}

View File

@ -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