Hey all, I’m new to elixir and getting the following error:
** (FunctionClauseError) no function clause matching in TSS.DriverStatuses.list_assignable_drivers_by_truck_load/1
So in my module, I define a get_remaining_time
function that takes a truck_load
:
defp get_remaining_time(truck_load) do
time_since_available = DriverStatuses.list_assignable_drivers_by_truck_load(truck_load)
Formatters.decorate_time_since_available(time_since_available)
end
This function uses the list_assignable_drivers_by_truck_load
in the DriverStatuses
module, which looks like this:
def list_assignable_drivers_by_truck_load(%TruckLoad{
well: %{id: well_id},
pull_point: pull_point
}) do
base_assignable_drivers_query()
|> apply_default_select(pull_point.point)
|> filter({:well_id, well_id})
|> sort({:distance_in_meters, :asc}, %{"pull_point_id" => pull_point.id})
|> preload(driver: [:trailer_type, driver_contract: [:carrier]])
|> Repo.all()
end
and then formats it using the decorate_time_since_available
function in the Formatters
module, which looks like this:
def decorate_time_since_available(%{driver_status: %{last_available_at: last_available_at}})
when not is_nil(last_available_at),
do:
humanize_time(DateTime.diff(DateTime.utc_now(), last_available_at), :seconds, :minutes) <>
" (hh:mm)"
def decorate_time_since_available(_), do: "N/A"
Finally, I am calling the function like so:
<CardInfo label="Time Since Available" title={{ get_remaining_time(@truck_load) }} small />
I think I’m not pattern matching correctly, but nothing I’ve tried is working. How can I fix this?
Thanks so much!!