Merge remote-tracking branch 'origin/refactor/migration-to-prisma' into refactor/songbook-api-integration

This commit is contained in:
rudi committed 2026-07-31 15:56:46 +02:00
commit 25a253116c
1 file changed
+18 -18
+18 -18
View File
@@ -20,10 +20,10 @@ export async function getSongBooks() {
}, },
}); });
return { success: true, songBooks }; return { success: true, status: 200, songBooks };
} catch (error) { } catch (error) {
console.error("Error in getSongBooks:", error); console.error("Error in getSongBooks:", error);
return { success: false, error: "Error while loading SongBooks" }; return { success: false, status: 500, error: "Error while loading SongBooks" };
} }
} }
@@ -60,13 +60,13 @@ export async function getSongBookById(id: number) {
}); });
if (!songBook) { if (!songBook) {
return { success: false, error: "SongBook not found" }; return { success: false, status: 404, error: "SongBook not found" };
} }
return { success: true, songBook }; return { success: true, status: 200, songBook };
} catch (error) { } catch (error) {
console.error("Error in getSongBookById:", error); console.error("Error in getSongBookById:", error);
return { success: false, error: "Error while loading SongBook" }; return { success: false, status: 500, error: "Error while loading SongBook" };
} }
} }
@@ -82,7 +82,7 @@ export async function searchSongBooksByTitle(query: string, limit: number = 20)
try { try {
const cleanQuery = query.trim(); const cleanQuery = query.trim();
if (!cleanQuery) { if (!cleanQuery) {
return { success: true, songBooks: [] }; return { success: true, status: 200, songBooks: [] };
} }
const songBooks = await prisma.songBook.findMany({ const songBooks = await prisma.songBook.findMany({
@@ -113,10 +113,10 @@ export async function searchSongBooksByTitle(query: string, limit: number = 20)
take: limit, take: limit,
}); });
return { success: true, songBooks }; return { success: true, status: 200, songBooks };
} catch (error) { } catch (error) {
console.error("Error in searchSongBooksByTitle:", error); console.error("Error in searchSongBooksByTitle:", error);
return { success: false, error: "Error while searching SongBooks" }; return { success: false, status: 500, error: "Error while searching SongBooks" };
} }
} }
@@ -141,14 +141,14 @@ export async function createSongBook(data: { title: string; language: string })
}, },
}); });
return { success: true, songBook }; return { success: true, status: 201, songBook };
} catch (error) { } catch (error) {
if (error.code === "P2002") { if (error.code === "P2002") {
return { success: false, error: "SongBook title already exists" }; return { success: false, status: 409, error: "SongBook title already exists" };
} }
console.error("Error in createSongBook:", error); console.error("Error in createSongBook:", error);
return { success: false, error: "Error while creating SongBook" }; return { success: false, status: 500, error: "Error while creating SongBook" };
} }
} }
@@ -178,7 +178,7 @@ export async function updateSongBook(
// If no fields to update were provided // If no fields to update were provided
if (Object.keys(updateData).length === 0) { if (Object.keys(updateData).length === 0) {
return { success: false, error: "No fields provided to update" }; return { success: false, status: 400, error: "No fields provided to update" };
} }
const songBook = await prisma.songBook.update({ const songBook = await prisma.songBook.update({
where: { id }, where: { id },
@@ -190,13 +190,13 @@ export async function updateSongBook(
}, },
}); });
return { success: true, songBook }; return { success: true, status: 200, songBook };
} catch (error: any) { } catch (error: any) {
if (error.code === "P2025") { if (error.code === "P2025") {
return { success: false, error: "SongBook not found" }; return { success: false, status: 404, error: "SongBook not found" };
} }
if (error.code === "P2002") { if (error.code === "P2002") {
return { success: false, error: "SongBook title already exists" }; return { success: false, status: 500, error: "SongBook title already exists" };
} }
console.error("Error in updateSongBook:", error); console.error("Error in updateSongBook:", error);
@@ -237,13 +237,13 @@ export async function deleteSongBook(id: number) {
}); });
if (!songBook) { if (!songBook) {
return { success: false, error: "SongBook not found" }; return { success: false, status: 404, error: "SongBook not found" };
} }
return { success: true, songBook }; return { success: true, status: 200, songBook };
} catch (error) { } catch (error) {
console.error("Error in deleteSongBook:", error); console.error("Error in deleteSongBook:", error);
return { success: false, error: "Error while deleting SongBook" }; return { success: false, status: 500, error: "Error while deleting SongBook" };
} }
} }