@@ -18,21 +18,35 @@ defmodule Algora.Jobs do
18
18
require Logger
19
19
20
20
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
36
50
|> Repo . all ( )
37
51
|> apply_preloads ( opts )
38
52
end
0 commit comments