Some API changes in Song. Added '.trim()' for better string processing
This commit is contained in:
1 parent
61f1eb5a2c
commit
66c9dc28fc
5 files changed
+123
-42
No files matched your search
@@ -1,9 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
getSongBooks,
|
||||
searchSongBooksByTitle,
|
||||
createSongBook,
|
||||
} from "@/lib/db/songbook";
|
||||
import { getSongBooks, searchSongBooksByTitle, createSongBook } from "@/lib/db/songbook";
|
||||
|
||||
|
||||
/**
|
||||
@@ -104,21 +100,16 @@ export async function GET(request: Request) {
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const name = body.name ? String(body.name).trim() : "";
|
||||
const language = body.language ? String(body.language).trim() : "";
|
||||
const data = await request.json();
|
||||
|
||||
if (!name || !language) {
|
||||
if (!data.name || !data.language) {
|
||||
return NextResponse.json(
|
||||
{ message: "Field 'name' and 'language' are required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const res = await createSongBook({
|
||||
title: name,
|
||||
language: language,
|
||||
});
|
||||
const res = await createSongBook(data);
|
||||
|
||||
if (!res.success) {
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in new issue
Block a user