diff --git a/lib/db/song.ts b/lib/db/song.ts index bd67dd6..ed55c36 100644 --- a/lib/db/song.ts +++ b/lib/db/song.ts @@ -20,10 +20,10 @@ export async function getSongs() { ], }); - return { success: true, songs }; + return { success: true, status: 200, songs }; } catch(error) { console.error("Error in getSongs", error); - return { success: false, error: "Error while loading Songs" }; + return { success: false, status: 500, error: "Error while loading Songs" }; } } @@ -56,13 +56,13 @@ export async function getSongById(id: number) { }); if (!song) { - return { success: false, error: "Song not found" }; + return { success: false, status: 404, error: "Song not found" }; } - return { success: true, song }; + return { success: true, status: 200, song }; } catch(error) { console.error("Error in getSongById", error); - return { success: false, error: "Error while loading Song" }; + return { success: false, status: 500, error: "Error while loading Song" }; } } @@ -106,10 +106,10 @@ export async function searchSongsByTitle(query: string, limit: number = 20) { take: limit, }); - return { success: true, songs }; + return { success: true, status: 200, songs }; } catch (error) { console.error("Error in searchSongsByTitle:", error); - return { success: false, error: "Error while searching Songs" }; + return { success: false, status: 500, error: "Error while searching Songs" }; } } @@ -132,17 +132,17 @@ export async function createSong(data: { title: string }) { }); if (!song) { - return { success: false, error: "Could not create song" }; + return { success: false, status: 500, error: "Could not create song" }; } - return { success: true, song }; + return { success: true, status: 201, song }; } catch(error) { console.error("Error in createSong", error); // P2002 = Unique Constraint Violation (username) if (error.code === "P2002") { - return { success: false, error: "Song already exists" }; + return { success: false, status: 409, error: "Song already exists" }; } - return { success: false, error: "Error while creating Song" }; + return { success: false, status: 500, error: "Error while creating Song" }; } } @@ -167,7 +167,7 @@ export async function updateSong( // 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 song = await prisma.song.update({ @@ -179,19 +179,19 @@ export async function updateSong( } }); - return { success: true, song }; + return { success: true, status: 200, song }; } catch (error) { console.error("Error in updateSong", error); // P2025 = Record to update not found if (error.code === "P2025") { - return { success: false, error: "Song not found" }; + return { success: false, status: 404, error: "Song not found" }; } // P2002 = Unique Constraint Violation (username) if (error.code === "P2002") { - return { success: false, error: "Song already exists" }; + return { success: false, status: 409, error: "Song already exists" }; } - return { success: false, error: "Error while updating Song" }; + return { success: false, status: 500, error: "Error while updating Song" }; } } @@ -211,14 +211,14 @@ export async function deleteSong(id: number) { } }); - return { success: true, song }; + return { success: true, status: 200, song }; } catch (error) { console.error("Error in deleteSong", error); // P2025 = Record to update not found if (error.code === "P2025") { - return { success: false, error: "Song not found" }; + return { success: false, status: 404, error: "Song not found" }; } - return { success: false, error: "Error while deleting Song" }; + return { success: false, status: 500, error: "Error while deleting Song" }; } }