feat(multi-tenant): configurar las 3 empresas oficiales (Telcotronics, XSYSTEM, DOMUS) y selector rapido de entorno

This commit is contained in:
2026-10-23 09:59:12 -05:00
parent 78f64291f5
commit 48323ea353
7 changed files with 137 additions and 39 deletions
+28
View File
@@ -69,4 +69,32 @@ router.post('/companies/update/:id', isSuperAdmin, async (req, res) => {
}
});
router.get('/switch/:id', isSuperAdmin, async (req, res) => {
try {
const targetId = parseInt(req.params.id);
const company = await Company.findById(targetId);
if (!company) {
req.flash('error_msg', 'Empresa no encontrada');
return res.redirect('/saas/companies');
}
req.session.user.company_id = company.id;
if (req.session.user.id) {
await User.update(req.session.user.id, { company_id: company.id });
}
req.flash('success_msg', `Cambiaste de entorno a: ${company.name}`);
const referrer = req.get('Referrer');
// Redirigir de forma segura al referrer o al dashboard
if (referrer && !referrer.includes('/login') && !referrer.includes('/logout')) {
return res.redirect(referrer);
}
res.redirect('/admin/dashboard');
} catch (error) {
console.error('Error switching company:', error);
req.flash('error_msg', 'Error al cambiar de empresa');
res.redirect('/saas/companies');
}
});
module.exports = router;