@@ -951,7 +951,7 @@ defmodule Algora.Bounties do
951951 from ( [ b ] in query , where: b . ticket_id == ^ ticket_id )
952952
953953 { :owner_id , owner_id } , query ->
954- from ( [ b ] in query , where: b . owner_id == ^ owner_id )
954+ from ( [ b , r: r ] in query , where: b . owner_id == ^ owner_id or r . user_id == ^ owner_id )
955955
956956 { :status , status } , query ->
957957 from ( [ b ] in query , where: b . status == ^ status )
@@ -1051,21 +1051,24 @@ defmodule Algora.Bounties do
10511051
10521052 open_bounties_query =
10531053 from b in Bounty ,
1054- join: u in assoc ( b , :owner ) ,
10551054 join: t in assoc ( b , :ticket ) ,
1056- where: u . id == ^ org_id ,
1055+ left_join: r in assoc ( t , :repository ) ,
1056+ where: b . owner_id == ^ org_id or r . user_id == ^ org_id ,
10571057 where: b . status == :open ,
10581058 # TODO: persist state as separate field
10591059 where: fragment ( "(?->>'state' != 'closed')" , t . provider_meta )
10601060
10611061 rewards_query =
1062- from t in Transaction ,
1063- where: t . type == :credit ,
1064- where: t . status == :succeeded ,
1065- join: lt in assoc ( t , :linked_transaction ) ,
1066- where: lt . type == :debit ,
1067- where: lt . status == :succeeded ,
1068- where: lt . user_id == ^ org_id
1062+ from tx in Transaction ,
1063+ where: tx . type == :credit ,
1064+ where: tx . status == :succeeded ,
1065+ join: ltx in assoc ( tx , :linked_transaction ) ,
1066+ left_join: b in assoc ( tx , :bounty ) ,
1067+ left_join: t in assoc ( b , :ticket ) ,
1068+ left_join: r in assoc ( t , :repository ) ,
1069+ where: ltx . type == :debit ,
1070+ where: ltx . status == :succeeded ,
1071+ where: ltx . user_id == ^ org_id or r . user_id == ^ org_id
10691072
10701073 rewarded_bounties_query = rewards_query |> where ( [ t ] , not is_nil ( t . bounty_id ) ) |> distinct ( :bounty_id )
10711074 rewarded_tips_query = rewards_query |> where ( [ t ] , not is_nil ( t . tip_id ) ) |> distinct ( :tip_id )
0 commit comments