Skip to content

Commit 0c3b27b

Browse files
committed
add option to filter by ids
1 parent ae5676e commit 0c3b27b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/algora/jobs/jobs.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ defmodule Algora.Jobs do
2020
def list_jobs(opts \\ []) do
2121
query =
2222
JobPosting
23+
|> maybe_filter_by_ids(opts[:ids])
2324
|> maybe_filter_by_status(opts)
2425
|> maybe_filter_by_user(opts)
2526
|> join(:inner, [j], u in User, on: u.id == j.user_id)
@@ -93,11 +94,18 @@ defmodule Algora.Jobs do
9394
where(query, [j, u], u.handle == ^handle)
9495
end
9596

97+
defp maybe_filter_by_ids(query, nil), do: query
98+
99+
defp maybe_filter_by_ids(query, ids) do
100+
where(query, [j], j.id in ^ids)
101+
end
102+
96103
defp maybe_filter_by_status(query, opts) do
97104
cond do
98105
opts[:status] == :all -> where(query, [j], j.status in [:active, :processing])
99106
opts[:user_id] -> where(query, [j], j.status in [:active, :processing])
100107
opts[:handle] -> where(query, [j, u], j.status in [:active, :processing])
108+
opts[:ids] -> where(query, [j, u], j.status in [:active, :processing])
101109
true -> where(query, [j], j.status in [:active])
102110
end
103111
end

0 commit comments

Comments
 (0)