Working on Standartisation.... #TODO

This commit is contained in:
Rudi committed 2026-08-27 18:07:42 +02:00
1 parent da4d67ea47
commit bdc864cf94
8 files changed
+104 -36

No files matched your search

+15 -8
View File
@@ -1,7 +1,14 @@
import { prisma } from "@/lib/db/prisma";
import { parseInt } from "@/lib/helper/checkvar";
import type * as API from "./response";
// For Error checking use this import: import { Prisma } from "@prisma/client";
interface Response {
success: boolean;
status: number;
songs?: [];
error?: string;
}
/**
* GetSongs
@@ -9,7 +16,7 @@ import { parseInt } from "@/lib/helper/checkvar";
*
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
*/
export async function getSongs() {
export async function getSongs(): Promise<API.GetSongsResponse> {
try{
const songs = await prisma.song.findMany({
select: {
@@ -35,7 +42,7 @@ export async function getSongs() {
* @param id - ID indicatin the song
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
*/
export async function getSongById(rawId: number) {
export async function getSongById(rawId: number): Promise<API.GetSongDetailedResponse> {
try{
const id = parseInt(rawId);
if (!id) {
@@ -78,13 +85,13 @@ export async function getSongById(rawId: number) {
*
* @param query - The search term for the song title.
* @param limit - Max number of songs returned for performance (default: 20).
* @returns @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
*/
export async function searchSongsByTitle(query: string, limit: number = 20) {
export async function searchSongsByTitle(query: string, limit: number = 20): Promise<API.GetSongsDelailedResponse> {
try {
const cleanQuery = query.trim();
if (!cleanQuery) {
return { success: true, songBooks: [] };
return { success: true, status: 200, songs: [] };
}
const songs = await prisma.song.findMany({
@@ -124,7 +131,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20) {
* @param data - object with title
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string}}
*/
export async function createSong(data: { title: string }) {
export async function createSong(data: { title: string }): Promise<API.CreateSongsResponse> {
try{
if(!data.title){
return { success: false, status: 400, error: "Field 'title' is required" };
@@ -164,7 +171,7 @@ export async function createSong(data: { title: string }) {
export async function updateSong(
rawId: number,
data: { title?: string }
) {
): Promise<API.CreateSongsResponse> {
try {
const id = parseInt(rawId);
if (!id) {
@@ -213,7 +220,7 @@ export async function updateSong(
* @param id - ID indicatin the song
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
*/
export async function deleteSong(rawId: number) {
export async function deleteSong(rawId: number): Promise<API.CreateSongsResponse> {
try {
const id = parseInt(rawId);
if (!id) {