fix(schedules): check dias_operacion in SchedulesView and update types

This commit is contained in:
2026-03-14 21:03:52 -05:00
parent 3ac554ad83
commit 75f581735b
2 changed files with 30 additions and 17 deletions

View File

@ -63,6 +63,7 @@ export interface BusSchedule {
schedule_type: ScheduleType schedule_type: ScheduleType
is_active: boolean is_active: boolean
is_published: boolean is_published: boolean
dias_operacion?: string[] | null
notes?: string notes?: string
created_at?: string created_at?: string
} }

View File

@ -48,28 +48,45 @@ function getBusStatus(timeStr: string): 'departing' | 'ontime' | 'upcoming' | 'p
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día // ── Calcular si el horario es "hoy" o "mañana" según tipo de día
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día // ── Calcular si el horario es "hoy" o "mañana" según tipo de día
const normalizar = (s: string | null | undefined) => (s || "").toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
function getScheduleDay(schedule: any): 'today' | 'tomorrow' | 'other' { function getScheduleDay(schedule: any): 'today' | 'tomorrow' | 'other' {
const now = new Date() const now = new Date()
const tomorrow = new Date(now) const tomorrow = new Date(now)
tomorrow.setDate(now.getDate() + 1) tomorrow.setDate(now.getDate() + 1)
const dias = ['domingo', 'lunes', 'martes', 'miercoles', 'jueves', 'viernes', 'sabado']
const hoyStr = normalizar(dias[now.getDay()])
const mañanaStr = normalizar(dias[tomorrow.getDay()])
const diasOP = schedule.dias_operacion as string[] | null
if (diasOP && Array.isArray(diasOP) && diasOP.length > 0) {
const isToday = diasOP.some(d => {
const dNorm = normalizar(d)
return dNorm === 'todos' || dNorm === hoyStr
})
if (isToday) return 'today'
const isTomorrow = diasOP.some(d => {
const dNorm = normalizar(d)
return dNorm === 'todos' || dNorm === mañanaStr
})
if (isTomorrow) return 'tomorrow'
return 'other'
}
const getDayType = (date: Date) => { const getDayType = (date: Date) => {
const dow = date.getDay() // 0=Dom, 6=Sab const dow = date.getDay()
return (dow === 0 || dow === 6) ? 'weekend' : 'weekday' return (dow === 0 || dow === 6) ? 'weekend' : 'weekday'
} }
const todayType = getDayType(now) const todayType = getDayType(now)
const tomorrowType = getDayType(tomorrow) const tomorrowType = getDayType(tomorrow)
// Comparar con el tipo del horario
// Nota: Si el horario es 'todos', cuenta para hoy y mañana (pero priorizamos hoy si pides hoy)
const type = (schedule.schedule_type as string) || 'todos' const type = (schedule.schedule_type as string) || 'todos'
const isToday = type === todayType || type === 'todos' if (type === todayType || type === 'todos') return 'today'
const isTomorrow = type === tomorrowType || type === 'todos' if (type === tomorrowType || type === 'todos') return 'tomorrow'
if (isToday) return 'today'
if (isTomorrow) return 'tomorrow'
if (type === 'holiday') return 'other' if (type === 'holiday') return 'other'
return 'other' return 'other'
@ -94,12 +111,7 @@ const filteredSchedules = computed(() => {
const hhmmAhora = now.getHours() * 100 + now.getMinutes() const hhmmAhora = now.getHours() * 100 + now.getMinutes()
return scheduleStore.schedules.filter(s => { return scheduleStore.schedules.filter(s => {
const type = (s.schedule_type as string) || 'todos' const dayStatus = getScheduleDay(s)
const todayType = (now.getDay() === 0 || now.getDay() === 6) ? 'weekend' : 'weekday'
const tomorrowType = (tomorrow.getDay() === 0 || tomorrow.getDay() === 6) ? 'weekend' : 'weekday'
const isActuallyToday = type === todayType || type === 'todos'
const isActuallyTomorrow = type === tomorrowType || type === 'todos'
// Filtro Hoy: Es hoy Y no ha pasado (o es de los que dice salir en este rango) // Filtro Hoy: Es hoy Y no ha pasado (o es de los que dice salir en este rango)
if (dayFilter.value === 'today') { if (dayFilter.value === 'today') {
@ -108,12 +120,12 @@ const filteredSchedules = computed(() => {
const m = parseInt(mStr || '0') const m = parseInt(mStr || '0')
const hhmmSched = h * 100 + m const hhmmSched = h * 100 + m
const isPassed = hhmmSched < hhmmAhora - 2 // margen de 2 min const isPassed = hhmmSched < hhmmAhora - 2 // margen de 2 min
return isActuallyToday && !isPassed return dayStatus === 'today' && !isPassed
} }
// Filtro Mañana: Es mañana (sin importar si pasó la hora hoy) // Filtro Mañana: Es mañana (sin importar si pasó la hora hoy)
if (dayFilter.value === 'tomorrow') { if (dayFilter.value === 'tomorrow') {
return isActuallyTomorrow return dayStatus === 'tomorrow'
} }
// Filtro Todos: Mostrar todo // Filtro Todos: Mostrar todo