I have app in next JS with typescript. I want upload app on vercel but this error occurs. I have no idea what is wrong in my /api/favourites/drivingSchoolId.
I have got that problem is related with my route.ts but it doesnt make any sense.
Error message:
/api/favourites/drivingSchoolId/route.ts
import { NextResponse } from "next/server";
import getCurrentUser from "@/app/actions/getCurrentUser";
import prisma from "@/app/libs/prismadb";
interface IParams {
drivingSchoolId?: string;
}
export async function POST(request: Request, { params }: { params: IParams }) {
const currentUser = await getCurrentUser();
if (!currentUser) return NextResponse.error();
const { drivingSchoolId } = params;
if (!drivingSchoolId) {
return NextResponse.json({ success: true, message: "Tato autoškola není dostupná" }, { status: 400 });
}
const alreadyExists = await prisma.user_favourite_car_driving_school.findFirst({
where: {
AND: [{ user_id: currentUser.user_id }, { driving_school_id: Number(drivingSchoolId) }],
},
});
if (alreadyExists) return NextResponse.json({ success: true, message: "Počkejte chvílu, ukládám záznam" }, { status: 400 });
await prisma.user_favourite_car_driving_school.create({
data: {
user_id: currentUser.user_id,
driving_school_id: Number(drivingSchoolId),
},
});
return NextResponse.json({ success: true, message: "Označeno jako oblíbené" }, { status: 200 });
}
export async function DELETE(request: Request, { params }: { params: IParams }) {
const currentUser = await getCurrentUser();
if (!currentUser) return NextResponse.error();
const { drivingSchoolId } = params;
if (!drivingSchoolId) return NextResponse.json({ success: true, message: "Tato autoškola není dostupná" }, { status: 400 });
await prisma.user_favourite_car_driving_school.deleteMany({
where: {
AND: [{ user_id: currentUser.user_id }, { driving_school_id: Number(drivingSchoolId) }],
},
});
return NextResponse.json({ success: true, message: "Zrušeno oblíbené" }, { status: 200 });
}