흐름
import { NextResponse } from 'next/server';
import getCurrentUser from '@/app/actions/getCurrentUser';
import prisma from '@/app/libs/prismadb';
interface IParams {
reservationId?: string;
}
export async function DELETE(
request: Request,
{ params }: { params: IParams }
) {
const currentUser = await getCurrentUser();
if (!currentUser) {
return NextResponse.error();
}
const { reservationId } = params;
if (!reservationId || typeof reservationId !== 'string') {
throw new Error('Invalid Id');
}
const reservation = await prisma.reservation.deleteMany({
where: {
id: reservationId,
OR: [{ userId: currentUser.id }, { listing: { userId: currentUser.id } }],
},
});
return NextResponse.json(reservation);
}
예약을 취소하고 상세페이지에 달력 페이지에 가보면 예약이 가능하다고 나온다!! 쩐다!