Skip to content

Commit

Permalink
hotfix(TimetableController): don't break if schedule has no times
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed Oct 5, 2023
1 parent c11e9a0 commit b038266
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/schedules/lib/schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ defmodule Schedules.Schedule do
}

def flag?(%Schedules.Schedule{flag?: value}), do: value

def no_times?(%Schedules.Schedule{arrival_time: at, departure_time: dt}),
do: is_nil(at) and is_nil(dt)
end

defmodule Schedules.ScheduleCondensed do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ defmodule SiteWeb.ScheduleController.TimetableController do
@spec timetable_schedules(Plug.Conn.t()) :: [Schedules.Schedule.t()]
defp timetable_schedules(%{assigns: %{date: date, route: route, direction_id: direction_id}}) do
case Schedules.Repo.by_route_ids([route.id], date: date, direction_id: direction_id) do
{:error, _} -> []
schedules -> schedules
{:error, _} ->
[]

schedules ->
schedules
|> Enum.reject(&Schedules.Schedule.no_times?/1)
end
end

Expand Down

0 comments on commit b038266

Please sign in to comment.