Статистика для дашборда #7
This commit is contained in:
@@ -13,8 +13,8 @@ list_users(Req) ->
|
||||
{ok, AdminId, Req1} ->
|
||||
case admin_utils:is_admin(AdminId) of
|
||||
true ->
|
||||
Users = core_user:list_users(),
|
||||
send_json(Req1, 200, [user_to_json(U) || U <- Users]);
|
||||
{ok, Users} = core_user:list_users(),
|
||||
send_json(Req1, 200, [user_to_map(U) || U <- Users]);
|
||||
false ->
|
||||
send_error(Req1, 403, <<"Admin access required">>)
|
||||
end;
|
||||
@@ -22,14 +22,23 @@ list_users(Req) ->
|
||||
send_error(Req1, Code, Message)
|
||||
end.
|
||||
|
||||
user_to_json(U) ->
|
||||
user_to_map(User) when is_map(User) ->
|
||||
#{
|
||||
id => U#user.id,
|
||||
email => U#user.email,
|
||||
role => U#user.role,
|
||||
status => U#user.status,
|
||||
created_at => datetime_to_iso8601(U#user.created_at),
|
||||
updated_at => datetime_to_iso8601(U#user.updated_at)
|
||||
id => maps:get(id, User),
|
||||
email => maps:get(email, User),
|
||||
role => maps:get(role, User, <<"user">>),
|
||||
status => maps:get(status, User, <<"active">>),
|
||||
created_at => datetime_to_iso8601(maps:get(created_at, User)),
|
||||
updated_at => datetime_to_iso8601(maps:get(updated_at, User))
|
||||
};
|
||||
user_to_map(User) ->
|
||||
#{
|
||||
id => User#user.id,
|
||||
email => User#user.email,
|
||||
role => atom_to_binary(User#user.role, utf8),
|
||||
status => atom_to_binary(User#user.status, utf8),
|
||||
created_at => datetime_to_iso8601(User#user.created_at),
|
||||
updated_at => datetime_to_iso8601(User#user.updated_at)
|
||||
}.
|
||||
|
||||
datetime_to_iso8601({{Y,M,D},{H,Min,S}}) ->
|
||||
|
||||
Reference in New Issue
Block a user