Fix datetime unserialize on admin logs view
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
8d7abe9ba0
commit
614cc1adc7
@ -128,11 +128,33 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp convert_changes_to_struct(struct, changes) do
|
defp convert_changes_to_struct(struct, changes) do
|
||||||
with data <- for({key, val} <- changes, into: %{}, do: {String.to_atom(key), val}) do
|
with changeset <- struct.__changeset__,
|
||||||
|
data <-
|
||||||
|
for(
|
||||||
|
{key, val} <- changes,
|
||||||
|
into: %{},
|
||||||
|
do: {String.to_atom(key), process_eventual_type(changeset, key, val)}
|
||||||
|
) do
|
||||||
struct(struct, data)
|
struct(struct, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# datetimes are not unserialized as DateTime/NaiveDateTime so we do it manually with changeset data
|
||||||
|
defp process_eventual_type(changeset, key, val) do
|
||||||
|
cond do
|
||||||
|
changeset[String.to_atom(key)] == :utc_datetime and not is_nil(val) ->
|
||||||
|
{:ok, datetime, _} = DateTime.from_iso8601(val)
|
||||||
|
datetime
|
||||||
|
|
||||||
|
changeset[String.to_atom(key)] == :naive_datetime and not is_nil(val) ->
|
||||||
|
{:ok, datetime} = NaiveDateTime.from_iso8601(val)
|
||||||
|
datetime
|
||||||
|
|
||||||
|
true ->
|
||||||
|
val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_dashboard(_parent, _args, %{context: %{current_user: %User{role: role}}})
|
def get_dashboard(_parent, _args, %{context: %{current_user: %User{role: role}}})
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
last_public_event_published =
|
last_public_event_published =
|
||||||
|
Loading…
Reference in New Issue
Block a user