Files
smalltown/app/api/districts/route.ts
2026-03-22 22:10:41 +08:00

21 lines
601 B
TypeScript

import { NextResponse } from 'next/server';
import pool from '@/lib/db';
export async function GET() {
let connection;
try {
connection = await pool.getConnection();
const [rows] = await connection.query<any[]>('SELECT name FROM districts ORDER BY sort_order, id');
const districts = rows.map((row: any) => row.name);
connection.release();
return NextResponse.json({ districts });
} catch (error) {
console.error('Get districts error:', error);
return NextResponse.json({ districts: [] });
} finally {
if (connection) connection.release();
}
}