creacion de vlans listo
This commit is contained in:
@@ -126,4 +126,29 @@ router.get('/db/table/:name', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// VLANs
|
||||
router.post('/vlans', async (req, res) => {
|
||||
try {
|
||||
const { id, nombre, descripcion } = req.body || {};
|
||||
const vid = Number(id);
|
||||
if (!Number.isInteger(vid) || vid <= 0) {
|
||||
return res.status(400).json({ ok: false, error: 'invalid_vlan_id' });
|
||||
}
|
||||
if (!nombre || String(nombre).trim() === '') {
|
||||
return res.status(400).json({ ok: false, error: 'nombre_required' });
|
||||
}
|
||||
await pool.query(
|
||||
'INSERT INTO vlans (id, nombre, descripcion) VALUES ($1, $2, $3)',
|
||||
[vid, String(nombre), descripcion != null ? String(descripcion) : null]
|
||||
);
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
if (e && e.code === '23505') {
|
||||
return res.status(409).json({ ok: false, error: 'vlan_exists' });
|
||||
}
|
||||
console.error('POST /api/vlans error:', e?.message || e);
|
||||
res.status(500).json({ ok: false, error: 'db_error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user