Files
food/app/api/restaurants/[id]/visits/route.ts
2026-03-21 11:57:08 +00:00

28 lines
746 B
TypeScript

import { NextResponse } from 'next/server'
import { readRestaurants, writeRestaurants } from '@/app/lib/restaurants'
import { Visit } from '@/app/types'
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const body = await request.json() as Omit<Visit, 'id'>
const restaurants = readRestaurants()
const index = restaurants.findIndex((r) => r.id === id)
if (index === -1) {
return NextResponse.json({ error: 'Not found' }, { status: 404 })
}
const newVisit: Visit = {
...body,
id: crypto.randomUUID(),
}
restaurants[index].visits.push(newVisit)
writeRestaurants(restaurants)
return NextResponse.json(newVisit, { status: 201 })
}