Actualizar server.js

This commit is contained in:
2026-02-24 10:55:43 +00:00
parent 522bae28b9
commit 0c699d0e31

View File

@@ -639,6 +639,7 @@ app.get("/public/portal/:token", async (req, res) => {
} catch (e) { res.status(500).json({ ok: false, error: "Error de servidor" }); } } catch (e) { res.status(500).json({ ok: false, error: "Error de servidor" }); }
}); });
// 2. Obtener huecos disponibles inteligentes (CON HORARIOS DINÁMICOS Y TRAMOS DE 1 HORA)
// 2. Obtener huecos disponibles inteligentes (CON HORARIOS DINÁMICOS Y TRAMOS DE 1 HORA) // 2. Obtener huecos disponibles inteligentes (CON HORARIOS DINÁMICOS Y TRAMOS DE 1 HORA)
app.get("/public/portal/:token/slots", async (req, res) => { app.get("/public/portal/:token/slots", async (req, res) => {
try { try {
@@ -777,46 +778,6 @@ app.get("/public/portal/:token/slots", async (req, res) => {
} catch (e) { console.error("Error Slots:", e); res.status(500).json({ ok: false }); } } catch (e) { console.error("Error Slots:", e); res.status(500).json({ ok: false }); }
}); });
const availableDays = [];
let d = new Date();
d.setDate(d.getDate() + 1);
let daysAdded = 0;
while(daysAdded < 10) {
if (d.getDay() !== 0) { // Omitir domingos
const dateStr = d.toISOString().split('T')[0];
const dayData = agendaMap[dateStr];
let isDayAllowed = true;
if (dayData && dayData.zone && targetZone) {
if (!dayData.zone.includes(targetZone) && !targetZone.includes(dayData.zone)) {
isDayAllowed = false;
}
}
if (isDayAllowed) {
const takenTimes = dayData ? dayData.times : [];
// Filtramos nuestra plantilla contra los huecos ocupados
const availMorning = morningBase.filter(t => !takenTimes.includes(t));
const availAfternoon = afternoonBase.filter(t => !takenTimes.includes(t));
if (availMorning.length > 0 || availAfternoon.length > 0) {
availableDays.push({
date: dateStr,
displayDate: d.toLocaleDateString('es-ES', { weekday: 'long', day: 'numeric', month: 'long' }),
morning: availMorning,
afternoon: availAfternoon
});
daysAdded++;
}
}
}
d.setDate(d.getDate() + 1);
}
res.json({ ok: true, days: availableDays });
} catch (e) { console.error("Error Slots:", e); res.status(500).json({ ok: false }); }
});
// 3. OBTENER SOLICITUDES PARA EL PANEL DEL ADMIN // 3. OBTENER SOLICITUDES PARA EL PANEL DEL ADMIN
app.get("/agenda/requests", authMiddleware, async (req, res) => { app.get("/agenda/requests", authMiddleware, async (req, res) => {
try { try {