fifteen/apps/web/app/api/admin/cities/[slug]/route.ts
2026-03-01 21:59:44 +01:00

41 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { sql } from "@/lib/db";
import { cacheDel } from "@/lib/cache";
import { getValhallaQueue } 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 the global Valhalla routing tile set.
// The valhalla-worker will delete the city's clipped PBF and rebuild
// tiles from all remaining cities' PBFs in one pass.
const valhallaQueue = getValhallaQueue();
await valhallaQueue.add(
"build-valhalla",
{ type: "build-valhalla", removeSlugs: [slug] },
{ attempts: 1, removeOnComplete: { age: 86400 } },
);
return NextResponse.json({ deleted: slug });
}