Actualizar server.js

This commit is contained in:
2026-02-15 16:35:57 +00:00
parent f17faa9177
commit 537d73221d

View File

@@ -650,18 +650,19 @@ app.get("/guilds", authMiddleware, async (req, res) => { try { const q = await p
app.post("/guilds", authMiddleware, async (req, res) => { try { const { name } = req.body; await pool.query("INSERT INTO guilds (name, owner_id) VALUES ($1, $2)", [name, req.user.accountId]); res.json({ ok: true }); } catch (e) { res.status(500).json({ ok: false }); } }); app.post("/guilds", authMiddleware, async (req, res) => { try { const { name } = req.body; await pool.query("INSERT INTO guilds (name, owner_id) VALUES ($1, $2)", [name, req.user.accountId]); res.json({ ok: true }); } catch (e) { res.status(500).json({ ok: false }); } });
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 }); } }); 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 }); } });
// --- NUEVO: Buscador Geográfico real desde DB --- // BUSCADOR GEOGRÁFICO: Consulta la tabla que poblaste en Adminer
app.get("/api/geo/municipios/:provincia", authMiddleware, async (req, res) => { app.get("/api/geo/municipios/:provincia", authMiddleware, async (req, res) => {
try { try {
const { provincia } = req.params; const { provincia } = req.params;
// Buscamos en la tabla master_geo_es filtrando por la provincia seleccionada
const q = await pool.query( const q = await pool.query(
"SELECT municipio, codigo_postal FROM master_geo_es WHERE provincia = $1 ORDER BY municipio ASC", "SELECT municipio, codigo_postal FROM master_geo_es WHERE provincia = $1 ORDER BY municipio ASC",
[provincia.toUpperCase()] [provincia.toUpperCase()]
); );
res.json({ ok: true, municipios: q.rows }); res.json({ ok: true, municipios: q.rows });
} catch (e) { } catch (e) {
console.error("Error geo:", e.message); console.error("Error al leer master_geo_es:", e.message);
res.status(500).json({ ok: false, error: "Error al consultar base geográfica" }); res.status(500).json({ ok: false });
} }
}); });