fix(dashboard): resolver metricas reales, endpoints profile y descriptor classmethod v3.6.2

This commit is contained in:
2026-10-19 12:12:19 -03:00
parent 44f4811171
commit 0b9fee0d66
14 changed files with 214 additions and 37 deletions
+3 -3
View File
@@ -85,9 +85,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
});
// Versiones institucionales del sistema
const APP_VERSION = '3.6.0';
const FRONTEND_VERSION = '3.6.0';
const BACKEND_VERSION = '3.6.0';
const APP_VERSION = '3.6.2';
const FRONTEND_VERSION = '3.6.2';
const BACKEND_VERSION = '3.6.2';
env.addGlobal('app_version', APP_VERSION);
env.addGlobal('frontend_version', FRONTEND_VERSION);
+58
View File
@@ -229,5 +229,63 @@ router.post(['/change_password', '/change-password'], requireAuth, async (req, r
}
});
// Mi Perfil de Usuario (GET)
router.get('/profile', requireAuth, async (req, res) => {
let userProfile = req.user || {};
try {
const resp = await req.apiClient.get('/auth/profile');
if (resp.data && resp.data.user) {
userProfile = { ...userProfile, ...resp.data.user };
}
} catch (err) {
console.warn('Could not fetch latest user profile from API:', err.message);
}
res.render('auth/profile', {
title: 'Mi Perfil — Edu-Space',
user: userProfile,
success: req.query.success || null,
error: req.query.error || null
});
});
// Guardar Preferencias de Perfil (POST)
router.post('/profile', requireAuth, async (req, res) => {
const { preferred_language, theme_preference } = req.body;
try {
await req.apiClient.post('/auth/profile', {
preferred_language: preferred_language || null,
theme_preference: theme_preference || 'auto'
});
// Actualizar datos en req.user si existe
if (req.user) {
req.user.preferred_language = preferred_language || null;
req.user.theme_preference = theme_preference || 'auto';
}
const msg = encodeURIComponent('Preferencias guardadas exitosamente.');
return res.redirect(`/auth/profile?success=${msg}`);
} catch (err) {
console.error('Error saving profile preferences:', err.response?.data || err.message);
const errMsg = encodeURIComponent(err.response?.data?.detail || err.response?.data?.message || 'Error al guardar las preferencias.');
return res.redirect(`/auth/profile?error=${errMsg}`);
}
});
// Cambiar Tema Visual rápido por AJAX
router.post(['/theme', '/api/user/theme'], requireAuth, async (req, res) => {
const theme = req.body.theme || (req.body.theme_preference);
try {
const resp = await req.apiClient.post('/auth/theme', { theme });
if (req.user) {
req.user.theme_preference = theme;
}
return res.json(resp.data);
} catch (err) {
return res.status(err.response?.status || 500).json(err.response?.data || { status: 'error', message: err.message });
}
});
module.exports = router;
+19 -17
View File
@@ -33,21 +33,21 @@ router.get('/', async (req, res) => {
];
}
const total_classrooms = backendStats.total_classrooms ?? 31;
const total_subjects = backendStats.active_subjects ?? backendStats.total_subjects ?? 12;
const total_users = backendStats.total_active_users ?? backendStats.total_users ?? 8;
const today_reservations = backendStats.today_reservations ?? 19;
const pending_count = backendStats.pending_count ?? 3;
const physical_classrooms = backendStats.physical_classrooms ?? Math.max(1, total_classrooms - 4);
const total_classrooms = backendStats.total_classrooms ?? 0;
const total_subjects = backendStats.active_subjects ?? backendStats.total_subjects ?? 0;
const total_users = backendStats.total_active_users ?? backendStats.total_users ?? 0;
const today_reservations = backendStats.today_reservations ?? 0;
const pending_count = backendStats.pending_count ?? 0;
const physical_classrooms = backendStats.physical_classrooms ?? total_classrooms;
const bedeliaData = apiData.bedelia || {};
const virtual_rooms_list = bedeliaData.virtual_rooms || apiData.virtual_rooms || [];
const virtual_classrooms_count = bedeliaData.virtual_rooms_count || virtual_rooms_list.length || backendStats.virtual_classrooms || 0;
const occupancy_rate = backendStats.occupancy_rate ?? 68;
const occupancy_rate = backendStats.occupancy_rate ?? 0;
const assigned_classrooms = backendStats.assigned_classrooms ?? 26;
const assigned_classrooms_pct = backendStats.assigned_classrooms_pct ?? 96.3;
const unassigned_classrooms = backendStats.unassigned_classrooms ?? 1;
const unassigned_classrooms_pct = backendStats.unassigned_classrooms_pct ?? 3.7;
const assigned_classrooms = backendStats.assigned_classrooms ?? 0;
const assigned_classrooms_pct = backendStats.assigned_classrooms_pct ?? 0;
const unassigned_classrooms = backendStats.unassigned_classrooms ?? 0;
const unassigned_classrooms_pct = backendStats.unassigned_classrooms_pct ?? 0;
const assigned_today_classrooms = backendStats.assigned_today_classrooms ?? 0;
const assigned_today_pct = backendStats.assigned_today_pct ?? 0;
@@ -103,11 +103,11 @@ router.get('/', async (req, res) => {
assigned_today_pct,
unassigned_today_classrooms,
unassigned_today_pct,
my_today_count: apiTodaySchedule ? Math.min(3, apiTodaySchedule.length) : 2,
my_total_reservations: 8,
my_today_count: backendStats.my_today_count ?? (apiTodaySchedule ? apiTodaySchedule.length : 0),
my_total_reservations: backendStats.my_total_reservations ?? 0,
virtual_rooms_count: virtual_classrooms_count,
today_classes_count: apiTodaySchedule ? Math.min(4, apiTodaySchedule.length) : 2,
milestones_count: apiMilestones ? apiMilestones.length : 3,
today_classes_count: apiTodaySchedule ? apiTodaySchedule.length : 0,
milestones_count: apiMilestones ? apiMilestones.length : 0,
filter_stats,
date_labels
};
@@ -146,10 +146,12 @@ router.get('/', async (req, res) => {
virtual_rooms_count: virtual_classrooms_count
};
} else if (role === 'docente') {
const myClasses = apiTodaySchedule ? apiTodaySchedule.slice(0, 3) : [];
const myClasses = Array.isArray(apiData.my_today_classes) && apiData.my_today_classes.length > 0
? apiData.my_today_classes
: (apiTodaySchedule ? apiTodaySchedule.filter(r => !req.user?.id || (r.user && r.user.id === req.user.id)) : []);
role_data = {
my_today_classes: myClasses,
virtual_classrooms: []
virtual_classrooms: virtual_rooms_list
};
} else if (role === 'alumno') {
const studentClasses = apiTodaySchedule ? apiTodaySchedule.slice(0, 4) : [];