Work in Songs and Songbooks API
This commit is contained in:
1 parent
e1eaea0f17
commit
4bdf03426c
6 files changed
+291
-13
No files matched your search
+16
-3
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib/db/prisma";
|
||||
import { parseInt } from "@/lib/helper/checkvar";
|
||||
// For Error checking use this import: import { Prisma } from "@prisma/client";
|
||||
|
||||
|
||||
@@ -34,8 +35,12 @@ 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(id: number) {
|
||||
export async function getSongById(rawId: number) {
|
||||
try{
|
||||
const id = parseInt(rawId);
|
||||
if (!id) {
|
||||
return { success: false, status: 400, error: "Id has to be Integer" };
|
||||
}
|
||||
const song = await prisma.song.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
@@ -153,10 +158,14 @@ export async function createSong(data: { title: string }) {
|
||||
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
||||
*/
|
||||
export async function updateSong(
|
||||
id: number,
|
||||
rawId: number,
|
||||
data: { title?: 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 } = {};
|
||||
|
||||
@@ -200,8 +209,12 @@ export async function updateSong(
|
||||
* @param id - ID indicatin the song
|
||||
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
||||
*/
|
||||
export async function deleteSong(id: number) {
|
||||
export async function deleteSong(rawId: number) {
|
||||
try {
|
||||
const id = parseInt(rawId);
|
||||
if (!id) {
|
||||
return { success: false, status: 400, error: "Id has to be Integer" };
|
||||
}
|
||||
const song = await prisma.song.delete({
|
||||
where: { id },
|
||||
select: {
|
||||
|
||||
Reference in new issue
Block a user