mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-22 07:52:43 +00:00
fix(back): event.ends_on can be nil
This commit is contained in:
parent
4489743853
commit
255c8fda67
2 changed files with 21 additions and 7 deletions
|
@ -374,7 +374,7 @@ defmodule Mobilizon.Events do
|
||||||
atom,
|
atom,
|
||||||
boolean,
|
boolean,
|
||||||
boolean | nil,
|
boolean | nil,
|
||||||
string | nil,
|
String.t() | nil,
|
||||||
float | nil
|
float | nil
|
||||||
) :: Page.t(Event.t())
|
) :: Page.t(Event.t())
|
||||||
def list_events(
|
def list_events(
|
||||||
|
@ -2029,11 +2029,20 @@ defmodule Mobilizon.Events do
|
||||||
defp event_filter_ends_on(query, nil, nil), do: query
|
defp event_filter_ends_on(query, nil, nil), do: query
|
||||||
|
|
||||||
defp event_filter_ends_on(query, %DateTime{} = after_datetime, nil) do
|
defp event_filter_ends_on(query, %DateTime{} = after_datetime, nil) do
|
||||||
where(query, [e], e.ends_on > ^after_datetime)
|
where(
|
||||||
|
query,
|
||||||
|
[e],
|
||||||
|
(is_nil(e.ends_on) and e.begins_on >= ^after_datetime) or
|
||||||
|
e.ends_on >= ^after_datetime
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp event_filter_ends_on(query, nil, %DateTime{} = before_datetime) do
|
defp event_filter_ends_on(query, nil, %DateTime{} = before_datetime) do
|
||||||
where(query, [e], e.ends_on < ^before_datetime)
|
where(
|
||||||
|
query,
|
||||||
|
[e],
|
||||||
|
(is_nil(e.ends_on) and e.begins_on <= ^before_datetime) or e.ends_on <= ^before_datetime
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp event_filter_ends_on(
|
defp event_filter_ends_on(
|
||||||
|
@ -2042,8 +2051,8 @@ defmodule Mobilizon.Events do
|
||||||
%DateTime{} = before_datetime
|
%DateTime{} = before_datetime
|
||||||
) do
|
) do
|
||||||
query
|
query
|
||||||
|> where([e], e.ends_on < ^before_datetime)
|
|> event_filter_ends_on(after_datetime, nil)
|
||||||
|> where([e], e.ends_on > ^after_datetime)
|
|> event_filter_ends_on(nil, before_datetime)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp event_order_by(query, order_by, direction)
|
defp event_order_by(query, order_by, direction)
|
||||||
|
@ -2145,6 +2154,10 @@ defmodule Mobilizon.Events do
|
||||||
# Handling the case where Repo.XXXX() return nil
|
# Handling the case where Repo.XXXX() return nil
|
||||||
def with_virtual_fields(nil), do: nil
|
def with_virtual_fields(nil), do: nil
|
||||||
|
|
||||||
|
# if envent has no end date, it can not be a long events
|
||||||
|
def with_virtual_fields(%Event{} = event) when is_nil(event.ends_on),
|
||||||
|
do: %{event | long_event: false}
|
||||||
|
|
||||||
# Handling the case where there is an event
|
# Handling the case where there is an event
|
||||||
# Using Repo.one(), for example
|
# Using Repo.one(), for example
|
||||||
def with_virtual_fields(%Event{} = event) do
|
def with_virtual_fields(%Event{} = event) do
|
||||||
|
|
|
@ -115,11 +115,12 @@ defmodule Mobilizon.Web.FeedControllerTest do
|
||||||
begins_on: DateTime.add(DateTime.utc_now(), 4, :day)
|
begins_on: DateTime.add(DateTime.utc_now(), 4, :day)
|
||||||
)
|
)
|
||||||
|
|
||||||
event3 =
|
event_in_the_past =
|
||||||
insert(:event,
|
insert(:event,
|
||||||
organizer_actor: actor,
|
organizer_actor: actor,
|
||||||
attributed_to: group,
|
attributed_to: group,
|
||||||
title: "Event Three",
|
title: "Event Three",
|
||||||
|
ends_on: DateTime.add(DateTime.utc_now(), -3, :day),
|
||||||
begins_on: DateTime.add(DateTime.utc_now(), -2, :day)
|
begins_on: DateTime.add(DateTime.utc_now(), -2, :day)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
|
||||||
|
|
||||||
Enum.each(entries, fn entry ->
|
Enum.each(entries, fn entry ->
|
||||||
assert entry.summary in [event1.title, event2.title]
|
assert entry.summary in [event1.title, event2.title]
|
||||||
refute entry.summary == event3.title
|
refute entry.summary == event_in_the_past.title
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert entry1.categories == [tag1.title]
|
assert entry1.categories == [tag1.title]
|
||||||
|
|
Loading…
Reference in a new issue