tududi/frontend/utils/notesService.ts
Chris f9b21dff0a
Fix today race condition (#75)
* Move frontend to root

* Fix backend issues

* Remove old routes

* Setup Dockerfile

* Fix today /tags multiplt requests issue

* Fix race condition on today's inbox widget

* Fix cors development issue

* Fix CORS for Dockerfile

* Fix dockerised settings for infinite loop

* Fix translation issues

* fixup! Fix translation issues

---------

Co-authored-by: Your Name <you@example.com>
2025-06-13 14:20:24 +03:00

52 lines
No EOL
1.5 KiB
TypeScript

import { Note } from "../entities/Note";
import { handleAuthResponse, getDefaultHeaders, getPostHeaders } from "./authUtils";
export const fetchNotes = async (): Promise<Note[]> => {
const response = await fetch("/api/notes", {
credentials: 'include',
headers: getDefaultHeaders(),
});
await handleAuthResponse(response, 'Failed to fetch notes.');
return await response.json();
};
export const createNote = async (noteData: Note): Promise<Note> => {
try {
console.log("Creating note with data:", JSON.stringify(noteData, null, 2));
const response = await fetch('/api/note', {
method: 'POST',
credentials: 'include',
headers: getPostHeaders(),
body: JSON.stringify(noteData),
});
await handleAuthResponse(response, 'Failed to create note.');
return await response.json();
} catch (error) {
console.error("Exception in createNote:", error);
throw error;
}
};
export const updateNote = async (noteId: number, noteData: Note): Promise<Note> => {
const response = await fetch(`/api/note/${noteId}`, {
method: 'PATCH',
credentials: 'include',
headers: getPostHeaders(),
body: JSON.stringify(noteData),
});
await handleAuthResponse(response, 'Failed to update note.');
return await response.json();
};
export const deleteNote = async (noteId: number): Promise<void> => {
const response = await fetch(`/api/note/${noteId}`, {
method: 'DELETE',
credentials: 'include',
headers: getDefaultHeaders(),
});
await handleAuthResponse(response, 'Failed to delete note.');
};