Fix note creation with project assignment (#927)

Transform project data in createNote to match updateNote behavior.
This ensures project_uid is properly extracted from nested project
object when creating notes with project associations.

Fixes #926
This commit is contained in:
Chris 2026-03-09 23:14:44 +02:00 committed by GitHub
parent fbe9ce0703
commit 358f577576
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,11 +21,25 @@ export const fetchNotes = async (): Promise<Note[]> => {
};
export const createNote = async (noteData: Note): Promise<Note> => {
// Transform project_id to project_uid if needed (same as updateNote)
const requestData = { ...noteData };
if (noteData.project && noteData.project.uid) {
requestData.project_uid = noteData.project.uid;
} else if (noteData.project_uid) {
// project_uid is already set, use it as-is
} else if (noteData.project_id && !noteData.project_uid) {
// Legacy: if only project_id is provided, we can't convert it to uid here
// This should not happen with the new implementation, but keeping for safety
console.warn(
'Note creation with project_id but no project_uid - this may fail'
);
}
const response = await fetch(getApiPath('note'), {
method: 'POST',
credentials: 'include',
headers: getPostHeaders(),
body: JSON.stringify(noteData),
body: JSON.stringify(requestData),
});
await handleAuthResponse(response, 'Failed to create note.');