Skip to content

Commit 9d81d22

Browse files
committed
feat: add option to remove dripped users
1 parent e83ce7a commit 9d81d22

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

lib/algora/jobs/jobs.ex

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,35 @@ defmodule Algora.Jobs do
1818
require Logger
1919

2020
def list_jobs(opts \\ []) do
21-
JobPosting
22-
|> maybe_filter_by_status(opts)
23-
|> maybe_filter_by_user(opts)
24-
|> join(:inner, [j], u in User, on: u.id == j.user_id)
25-
|> maybe_filter_by_handle(opts[:handle])
26-
|> maybe_filter_by_tech_stack(opts[:tech_stack])
27-
|> join(:left, [j], i in JobInterview, on: i.job_posting_id == j.id)
28-
|> join(:left, [j], m in JobMatch, on: m.job_posting_id == j.id)
29-
|> group_by([j, u, i, m], [u.contract_signed, j.id, j.inserted_at])
30-
|> order_by([j, u, i, m],
31-
desc: u.contract_signed,
32-
desc_nulls_last: max(i.inserted_at),
33-
desc: j.inserted_at
34-
)
35-
|> maybe_limit(opts[:limit])
21+
query =
22+
JobPosting
23+
|> maybe_filter_by_status(opts)
24+
|> maybe_filter_by_user(opts)
25+
|> join(:inner, [j], u in User, on: u.id == j.user_id)
26+
|> maybe_filter_by_handle(opts[:handle])
27+
|> maybe_filter_by_tech_stack(opts[:tech_stack])
28+
|> join(:left, [j], i in JobInterview, on: i.job_posting_id == j.id)
29+
|> join(:left, [j], m in JobMatch, on: m.job_posting_id == j.id)
30+
|> group_by([j, u, i, m], [u.contract_signed, j.id, j.inserted_at])
31+
|> order_by([j, u, i, m],
32+
desc: u.contract_signed,
33+
desc_nulls_last: max(i.inserted_at),
34+
desc: j.inserted_at
35+
)
36+
|> maybe_limit(opts[:limit])
37+
38+
query =
39+
if opts[:remove_dripped] do
40+
where(
41+
query,
42+
[j, u],
43+
u.contract_signed or fragment("not exists (select 1 from drips where drips.org_id = ?)", u.id)
44+
)
45+
else
46+
query
47+
end
48+
49+
query
3650
|> Repo.all()
3751
|> apply_preloads(opts)
3852
end

0 commit comments

Comments
 (0)