API work on SongbookSongs
This commit is contained in:
1 parent
4bdf03426c
commit
b060ab29cf
10 files changed
+347
-119
No files matched your search
+20
-4
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib/db/prisma";
|
||||
import { parseInt } from "@/lib/helper/checkvar";
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,8 +35,12 @@ export async function getSongBooks() {
|
||||
* @param id - ID indicating the songbook
|
||||
* @returns {"success": boolean, "songBook": object}
|
||||
*/
|
||||
export async function getSongBookById(id: number) {
|
||||
export async function getSongBookById(rawId: number) {
|
||||
try {
|
||||
const id = parseInt(rawId);
|
||||
if (!id) {
|
||||
return { success: false, status: 400, error: "Id has to be Integer" };
|
||||
}
|
||||
const songBook = await prisma.songBook.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
@@ -129,10 +134,13 @@ export async function searchSongBooksByTitle(query: string, limit: number = 20)
|
||||
*/
|
||||
export async function createSongBook(data: { title: string; language: string }) {
|
||||
try {
|
||||
if(!data.title){
|
||||
return { success: false, status: 400, error: "Field 'title' is required" };
|
||||
}
|
||||
const songBook = await prisma.songBook.create({
|
||||
data: {
|
||||
title: data.title.trim(),
|
||||
language: data.language.trim(),
|
||||
language: data.language?.trim() ?? "",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -161,10 +169,14 @@ export async function createSongBook(data: { title: string; language: string })
|
||||
* @returns {"success": boolean, "songBook": {"id": number, "title": string, "language": string}}
|
||||
*/
|
||||
export async function updateSongBook(
|
||||
id: number,
|
||||
rawId: number,
|
||||
data: { title?: string; language?: string }
|
||||
) {
|
||||
try {
|
||||
const id = parseInt(rawId);
|
||||
if (!id) {
|
||||
return { success: false, status: 400, error: "Id has to be Integer" };
|
||||
}
|
||||
// Prepare update fields dynamically
|
||||
const updateData: { title?: string; language?: string } = {};
|
||||
|
||||
@@ -211,8 +223,12 @@ export async function updateSongBook(
|
||||
* @param id - ID indicating the songbook
|
||||
* @returns {"success": boolean, "songBook": object}
|
||||
*/
|
||||
export async function deleteSongBook(id: number) {
|
||||
export async function deleteSongBook(rawId: number) {
|
||||
try {
|
||||
const id = parseInt(rawId);
|
||||
if (!id) {
|
||||
return { success: false, status: 400, error: "Id has to be Integer" };
|
||||
}
|
||||
const songBook = await prisma.songBook.delete({
|
||||
where: { id },
|
||||
select: {
|
||||
|
||||
Reference in new issue
Block a user