From 80f951680f516f092e33243a2bf0c0ed949f3f0f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 12 May 2021 18:22:20 +0200 Subject: [PATCH] Order actor organized events by begins_on Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 35271d836..997c41e37 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -421,7 +421,7 @@ defmodule Mobilizon.Events do @spec list_organized_events_for_actor(Actor.t(), integer | nil, integer | nil) :: Page.t() def list_organized_events_for_actor(%Actor{id: actor_id}, page \\ nil, limit \\ nil) do actor_id - |> event_for_actor_query() + |> event_for_actor_query(desc: :begins_on) |> preload_for_event() |> Page.build_page(page, limit) end @@ -1264,12 +1264,10 @@ defmodule Mobilizon.Events do end @spec event_for_actor_query(integer | String.t()) :: Ecto.Query.t() - defp event_for_actor_query(actor_id) do - from( - e in Event, - where: e.organizer_actor_id == ^actor_id, - order_by: [desc: :id] - ) + defp event_for_actor_query(actor_id, order_by \\ [desc: :id]) do + Event + |> where([e], e.organizer_actor_id == ^actor_id) + |> order_by([e], ^order_by) end @spec event_for_group_query(integer | String.t()) :: Ecto.Query.t()