Dorabiamy funkcjonalnosci w TV
This commit is contained in:
29
src/pages/api/range/has-streets.js
Normal file
29
src/pages/api/range/has-streets.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getDb } from "../db.js";
|
||||
|
||||
export async function GET({ request }) {
|
||||
const city = new URL(request.url).searchParams.get("city")?.trim() || "";
|
||||
|
||||
if (!city) {
|
||||
return new Response(JSON.stringify({ hasStreets: false }), {
|
||||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||||
});
|
||||
}
|
||||
|
||||
const db = getDb();
|
||||
|
||||
const row = db
|
||||
.prepare(
|
||||
`SELECT COUNT(*) AS cnt
|
||||
FROM ranges
|
||||
WHERE LOWER(city) = LOWER(?)
|
||||
AND TRIM(street) <> ''`
|
||||
)
|
||||
.get(city);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ hasStreets: row.cnt > 0 }),
|
||||
{
|
||||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user