Статистика для дашборда #7
This commit is contained in:
@@ -13,16 +13,8 @@ get_stats(Req) ->
|
||||
{ok, AdminId, Req1} ->
|
||||
case admin_utils:is_admin(AdminId) of
|
||||
true ->
|
||||
Stats = #{
|
||||
users => count_users(),
|
||||
calendars => count_calendars(),
|
||||
events => count_events(),
|
||||
bookings => count_bookings(),
|
||||
reviews => count_reviews(),
|
||||
reports => count_reports(),
|
||||
tickets => count_tickets(),
|
||||
subscriptions => count_subscriptions()
|
||||
},
|
||||
{ok, Admin} = core_admin:get_by_id(AdminId),
|
||||
Stats = logic_stats:get_stats(Admin#admin.role, AdminId),
|
||||
send_json(Req1, 200, Stats);
|
||||
false ->
|
||||
send_error(Req1, 403, <<"Admin access required">>)
|
||||
@@ -31,15 +23,6 @@ get_stats(Req) ->
|
||||
send_error(Req1, Code, Message)
|
||||
end.
|
||||
|
||||
count_users() -> length(mnesia:dirty_match_object(#user{_ = '_'})).
|
||||
count_calendars() -> length(mnesia:dirty_match_object(#calendar{_ = '_'})).
|
||||
count_events() -> length(mnesia:dirty_match_object(#event{is_instance = false, _ = '_'})).
|
||||
count_bookings() -> length(mnesia:dirty_match_object(#booking{_ = '_'})).
|
||||
count_reviews() -> length(mnesia:dirty_match_object(#review{_ = '_'})).
|
||||
count_reports() -> length(mnesia:dirty_match_object(#report{_ = '_'})).
|
||||
count_tickets() -> length(mnesia:dirty_match_object(#ticket{_ = '_'})).
|
||||
count_subscriptions() -> length(mnesia:dirty_match_object(#subscription{_ = '_'})).
|
||||
|
||||
send_json(Req, Status, Data) ->
|
||||
Body = jsx:encode(Data),
|
||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
||||
|
||||
Reference in New Issue
Block a user