Skip to content

Commit 17c6e45

Browse files
committed
feat: top earners by org query
1 parent 01fcb0a commit 17c6e45

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/algora/accounts/accounts.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule Algora.Accounts do
1414

1515
@type criterion ::
1616
{:id, binary()}
17+
| {:org_id, binary()}
1718
| {:limit, non_neg_integer()}
1819
| {:handle, String.t()}
1920
| {:handles, [String.t()]}
@@ -76,9 +77,17 @@ defmodule Algora.Accounts do
7677
|> where([u], u.type == :individual)
7778
|> select([b], b.id)
7879

80+
filter_org_id =
81+
if org_id = criteria[:org_id],
82+
do: dynamic([linked_transaction: lt], lt.user_id == ^org_id),
83+
else: true
84+
7985
earnings_query =
8086
from t in Transaction,
8187
where: t.type == :credit and t.status == :succeeded,
88+
left_join: lt in assoc(t, :linked_transaction),
89+
as: :linked_transaction,
90+
where: ^filter_org_id,
8291
group_by: t.user_id,
8392
select: %{
8493
user_id: t.user_id,

lib/algora_web/live/org/dashboard_public_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule AlgoraWeb.Org.DashboardPublicLive do
1212
org = Organizations.get_org_by_handle!(handle)
1313
open_bounties = Bounties.list_bounties(owner_id: org.id, status: :open, limit: 5)
1414
completed_bounties = Bounties.list_bounties(owner_id: org.id, status: :paid, limit: 5)
15-
top_earners = Accounts.list_developers(limit: 10)
15+
top_earners = Accounts.list_developers(org_id: org.id, limit: 10, min_earnings: Money.zero(:USD))
1616
stats = Bounties.fetch_stats(org.id)
1717

1818
socket =

0 commit comments

Comments
 (0)