import { NextRequest, NextResponse } from "next/server"; import { sql } from "@/lib/db"; import { cacheDel } from "@/lib/cache"; import { getValhallaQueue, getValhallaTransitQueue } from "@/lib/queue"; export const runtime = "nodejs"; export async function DELETE( _req: NextRequest, { params }: { params: Promise<{ slug: string }> }, ) { const { slug } = await params; const result = await Promise.resolve(sql` DELETE FROM cities WHERE slug = ${slug} RETURNING slug `); if (result.length === 0) { return NextResponse.json({ error: "City not found" }, { status: 404 }); } // Invalidate all caches for this city await Promise.all([ cacheDel("api:cities:*"), cacheDel(`api:grid:*${slug}*`), cacheDel(`api:pois:*${slug}*`), cacheDel(`api:stats:*${slug}*`), ]); // Remove city from both Valhalla routing tile sets (road + transit). const rebuildOpts = { attempts: 1, removeOnComplete: { age: 86400 } } as const; const rebuildData = { type: "build-valhalla" as const, removeSlugs: [slug] }; await Promise.all([ getValhallaQueue().add("build-valhalla", rebuildData, rebuildOpts), getValhallaTransitQueue().add("build-valhalla", rebuildData, rebuildOpts), ]); return NextResponse.json({ deleted: slug }); }