Paar Verbesserungen

This commit is contained in:
rudi committed 2026-07-31 09:58:59 +02:00
1 parent 87a894db1e
commit df169d2943
1 file changed
+7 -8
+7 -8
View File
@@ -1,5 +1,5 @@
import { prisma } from "@/lib/db/prisma";
// For Error checking use this import: import { Prisma } from "@prisma/client";
/**
@@ -76,16 +76,16 @@ export async function getSongById(id: number) {
*/
export async function searchSongsByTitle(query: string, limit: number = 20) {
try {
// If string is empty
if (!query || query.trim() === "") {
return { success: true, songs: [] };
const cleanQuery = query.trim();
if (!cleanQuery) {
return { success: true, songBooks: [] };
}
const songs = await prisma.song.findMany({
where: {
title: {
contains: query.trim(),
mode: "insensitive", // Groß-/Kleinschreibung ignorieren
mode: "insensitive", // Textsearch
},
},
select: {
@@ -103,7 +103,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20) {
},
},
},
take: limit, // limit out
take: limit,
});
return { success: true, songs };
@@ -138,7 +138,6 @@ export async function createSong(data: { title: string }) {
return { success: true, 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" };
@@ -151,7 +150,7 @@ export async function createSong(data: { title: string }) {
* UpdateSong
* Updates an existing song and returns the updated song
* @param id - ID indicatin the song
* @param data - object with optionally username, password and role
* @param data - object with title
* @returns {"success": boolean, "song": {"id": number, "title": string}}
*/
export async function updateSong(