27 lines
808 B
TypeScript
27 lines
808 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import { readRestaurants, writeRestaurants } from '@/app/lib/restaurants'
|
|
|
|
export async function DELETE(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string; visitId: string }> }
|
|
) {
|
|
const { id, visitId } = await params
|
|
const restaurants = readRestaurants()
|
|
const index = restaurants.findIndex((r) => r.id === id)
|
|
|
|
if (index === -1) {
|
|
return NextResponse.json({ error: 'Restaurant not found' }, { status: 404 })
|
|
}
|
|
|
|
const visitIndex = restaurants[index].visits.findIndex((v) => v.id === visitId)
|
|
|
|
if (visitIndex === -1) {
|
|
return NextResponse.json({ error: 'Visit not found' }, { status: 404 })
|
|
}
|
|
|
|
restaurants[index].visits.splice(visitIndex, 1)
|
|
writeRestaurants(restaurants)
|
|
|
|
return NextResponse.json({ success: true })
|
|
}
|