import axios, { AxiosError } from 'axios'; import { Note } from '@/types'; import { toast } from 'vue-sonner'; const API_URL = '/api/notes'; export default { /** * Retrieves all notes * @returns Promise */ async getNotesForModel(modelType: string, notableId: number): Promise { try { const response = await axios.get(`${API_URL}/${modelType}/${notableId}`) return response.data; } catch (error) { toast.error('Fehler beim Laden der Notizen', { description: (error as AxiosError).message }) console.error(error) } return null }, /** * Creates a new note * @param note - The note data to create * @returns Promise */ async createNote(note: Partial): Promise { const response = await axios.post(API_URL, note); return response.data; }, /** * Update an existing note * @param note - The Note object to update * @returns */ async updateNote(note: Partial): Promise { const response = await axios.put(`${API_URL}/${note.id}`, note); return response.data; }, /** * Deletes a note by ID * @param noteId - The id of the note to delete * @returns boolean - True if the note was deleted, false otherwise */ async deleteNote(noteId: number): Promise { try { const response = await axios.delete(`${API_URL}/${noteId}`); return true; } catch (error) { toast.error('Fehler beim LĂ–schen der Notiz', { description: (error as AxiosError).message }) console.error(error) return false; } }, };