Paar Verbesserungen
This commit is contained in:
1 parent
87a894db1e
commit
df169d2943
1 file changed
+7
-8
+7
-8
@@ -1,5 +1,5 @@
|
|||||||
import { prisma } from "@/lib/db/prisma";
|
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) {
|
export async function searchSongsByTitle(query: string, limit: number = 20) {
|
||||||
try {
|
try {
|
||||||
// If string is empty
|
const cleanQuery = query.trim();
|
||||||
if (!query || query.trim() === "") {
|
if (!cleanQuery) {
|
||||||
return { success: true, songs: [] };
|
return { success: true, songBooks: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
where: {
|
where: {
|
||||||
title: {
|
title: {
|
||||||
contains: query.trim(),
|
contains: query.trim(),
|
||||||
mode: "insensitive", // Groß-/Kleinschreibung ignorieren
|
mode: "insensitive", // Textsearch
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
@@ -103,7 +103,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
take: limit, // limit out
|
take: limit,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, songs };
|
return { success: true, songs };
|
||||||
@@ -138,7 +138,6 @@ export async function createSong(data: { title: string }) {
|
|||||||
return { success: true, song };
|
return { success: true, song };
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.error("Error in createSong", error);
|
console.error("Error in createSong", error);
|
||||||
}
|
|
||||||
// P2002 = Unique Constraint Violation (username)
|
// P2002 = Unique Constraint Violation (username)
|
||||||
if (error.code === "P2002") {
|
if (error.code === "P2002") {
|
||||||
return { success: false, error: "Song already exists" };
|
return { success: false, error: "Song already exists" };
|
||||||
@@ -151,7 +150,7 @@ export async function createSong(data: { title: string }) {
|
|||||||
* UpdateSong
|
* UpdateSong
|
||||||
* Updates an existing song and returns the updated song
|
* Updates an existing song and returns the updated song
|
||||||
* @param id - ID indicatin the 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}}
|
* @returns {"success": boolean, "song": {"id": number, "title": string}}
|
||||||
*/
|
*/
|
||||||
export async function updateSong(
|
export async function updateSong(
|
||||||
|
|||||||
Reference in new issue
Block a user