From 0c699d0e31b30c5f7dce56ae89367b8e291bc39a Mon Sep 17 00:00:00 2001 From: marsalva Date: Tue, 24 Feb 2026 10:55:43 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/server.js b/server.js index b72aca5..1bf127a 100644 --- a/server.js +++ b/server.js @@ -639,6 +639,7 @@ app.get("/public/portal/:token", async (req, res) => { } 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) app.get("/public/portal/:token/slots", async (req, res) => { 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 }); } }); - 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 app.get("/agenda/requests", authMiddleware, async (req, res) => { try {