@@ -779,39 +779,42 @@ defmodule Algora.Bounties do
779
779
where: u . id == ^ org_id ,
780
780
where: b . status == :open
781
781
782
- rewarded_bounties_query =
783
- from b in Bounty ,
784
- join: u in assoc ( b , :owner ) ,
785
- where: u . id == ^ org_id ,
786
- where: b . status == :paid
787
-
788
- rewarded_users_query =
782
+ rewards_query =
789
783
from t in Transaction ,
790
784
where: t . type == :credit ,
791
785
where: t . status == :succeeded ,
792
786
join: lt in assoc ( t , :linked_transaction ) ,
793
787
where: lt . type == :debit ,
794
788
where: lt . status == :succeeded ,
795
- where: lt . user_id == ^ org_id ,
796
- distinct: :user_id
789
+ where: lt . user_id == ^ org_id
790
+
791
+ rewarded_bounties_query = distinct ( rewards_query , :bounty_id )
792
+ rewarded_tips_query = distinct ( rewards_query , :tip_id )
793
+ rewarded_contracts_query = distinct ( rewards_query , :contract_id )
794
+ rewarded_users_query = distinct ( rewards_query , :user_id )
797
795
796
+ # TODO: this is not correct, we need to get the users who have received rewards only in the last month
798
797
rewarded_users_last_month_query =
799
798
where ( rewarded_users_query , [ t ] , t . succeeded_at >= fragment ( "NOW() - INTERVAL '1 month'" ) )
800
799
801
800
members_query = Member . filter_by_org_id ( Member , org_id )
802
801
open_bounties = Repo . aggregate ( open_bounties_query , :count , :id )
803
802
open_bounties_amount = Repo . aggregate ( open_bounties_query , :sum , :amount ) || zero_money
804
- total_awarded = Repo . aggregate ( rewarded_bounties_query , :sum , :amount ) || zero_money
805
- completed_bounties = Repo . aggregate ( rewarded_bounties_query , :count , :id )
803
+ total_awarded_amount = Repo . aggregate ( rewards_query , :sum , :net_amount ) || zero_money
804
+ rewarded_bounties_count = Repo . aggregate ( rewarded_bounties_query , :count , :id )
805
+ rewarded_tips_count = Repo . aggregate ( rewarded_tips_query , :count , :id )
806
+ rewarded_contracts_count = Repo . aggregate ( rewarded_contracts_query , :count , :id )
806
807
solvers_count_last_month = Repo . aggregate ( rewarded_users_last_month_query , :count , :user_id )
807
808
solvers_count = Repo . aggregate ( rewarded_users_query , :count , :user_id )
808
809
members_count = Repo . aggregate ( members_query , :count , :id )
809
810
810
811
% {
811
812
open_bounties_amount: open_bounties_amount ,
812
813
open_bounties_count: open_bounties ,
813
- total_awarded: total_awarded ,
814
- completed_bounties_count: completed_bounties ,
814
+ total_awarded_amount: total_awarded_amount ,
815
+ rewarded_bounties_count: rewarded_bounties_count ,
816
+ rewarded_tips_count: rewarded_tips_count ,
817
+ rewarded_contracts_count: rewarded_contracts_count ,
815
818
solvers_count: solvers_count ,
816
819
solvers_diff: solvers_count - solvers_count_last_month ,
817
820
members_count: members_count
0 commit comments