-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.ts
34 lines (29 loc) · 864 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 reservation id')
}
const reservation = await prisma.reservation.deleteMany({
where: {
id: reservationId,
OR: [
{ userId: currentUser.id },
{ listing: { userId: currentUser.id } }
]
}
})
return NextResponse.json(reservation)
}