Merge remote-tracking branch 'origin/refactor/migration-to-prisma' into refactor/songbook-api-integration
This commit is contained in:
commit
25a253116c
1 file changed
+18
-18
+18
-18
@@ -20,10 +20,10 @@ export async function getSongBooks() {
|
||||
},
|
||||
});
|
||||
|
||||
return { success: true, songBooks };
|
||||
return { success: true, status: 200, songBooks };
|
||||
} catch (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) {
|
||||
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) {
|
||||
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 {
|
||||
const cleanQuery = query.trim();
|
||||
if (!cleanQuery) {
|
||||
return { success: true, songBooks: [] };
|
||||
return { success: true, status: 200, songBooks: [] };
|
||||
}
|
||||
|
||||
const songBooks = await prisma.songBook.findMany({
|
||||
@@ -113,10 +113,10 @@ export async function searchSongBooksByTitle(query: string, limit: number = 20)
|
||||
take: limit,
|
||||
});
|
||||
|
||||
return { success: true, songBooks };
|
||||
return { success: true, status: 200, songBooks };
|
||||
} catch (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) {
|
||||
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);
|
||||
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 (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({
|
||||
where: { id },
|
||||
@@ -190,13 +190,13 @@ export async function updateSongBook(
|
||||
},
|
||||
});
|
||||
|
||||
return { success: true, songBook };
|
||||
return { success: true, status: 200, songBook };
|
||||
} catch (error: any) {
|
||||
if (error.code === "P2025") {
|
||||
return { success: false, error: "SongBook not found" };
|
||||
return { success: false, status: 404, error: "SongBook not found" };
|
||||
}
|
||||
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);
|
||||
@@ -237,13 +237,13 @@ export async function deleteSongBook(id: number) {
|
||||
});
|
||||
|
||||
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) {
|
||||
console.error("Error in deleteSongBook:", error);
|
||||
return { success: false, error: "Error while deleting SongBook" };
|
||||
return { success: false, status: 500, error: "Error while deleting SongBook" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user