Actualizar server.js
This commit is contained in:
13
server.js
13
server.js
@@ -651,13 +651,20 @@ app.post("/guilds", authMiddleware, async (req, res) => { try { const { name } =
|
||||
app.delete("/guilds/:id", authMiddleware, async (req, res) => { try { await pool.query("DELETE FROM guilds WHERE id=$1 AND owner_id=$2", [req.params.id, req.user.accountId]); res.json({ ok: true }); } catch (e) { res.status(500).json({ ok: false }); } });
|
||||
|
||||
// BUSCADOR GEOGRÁFICO: Consulta la tabla que poblaste en Adminer
|
||||
// BUSCADOR GEOGRÁFICO MEJORADO (Ignora tildes automáticamente)
|
||||
app.get("/api/geo/municipios/:provincia", authMiddleware, async (req, res) => {
|
||||
try {
|
||||
const { provincia } = req.params;
|
||||
// Buscamos en la tabla master_geo_es filtrando por la provincia seleccionada
|
||||
let { provincia } = req.params;
|
||||
|
||||
// Normalizamos la entrada: quitamos tildes y ponemos en mayúsculas
|
||||
// Ejemplo: "CÁDIZ" -> "CADIZ"
|
||||
const provClean = provincia.toUpperCase()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "");
|
||||
|
||||
const q = await pool.query(
|
||||
"SELECT municipio, codigo_postal FROM master_geo_es WHERE provincia = $1 ORDER BY municipio ASC",
|
||||
[provincia.toUpperCase()]
|
||||
[provClean]
|
||||
);
|
||||
res.json({ ok: true, municipios: q.rows });
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user