Skip to content

Commit def6be0

Browse files
committed
feat: refactor list_user_approved_matches to use query chaining for improved readability and performance
1 parent 7d72c34 commit def6be0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/algora/matches/matches.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,19 @@ defmodule Algora.Matches do
169169
end
170170

171171
def list_user_approved_matches(user_id) do
172-
list_job_matches(
173-
user_id: user_id,
174-
status: [:approved, :highlighted],
175-
order_by: [asc: :candidate_approved_at, asc: :candidate_bookmarked_at, desc: :candidate_discarded_at],
176-
preload: [job_posting: :user]
172+
JobMatch
173+
|> filter_by_user_id(user_id)
174+
|> filter_by_status([:approved, :highlighted])
175+
|> join(:inner, [m], j in assoc(m, :job_posting), as: :j)
176+
|> order_by([m],
177+
asc: m.candidate_approved_at,
178+
asc: m.candidate_bookmarked_at,
179+
desc: m.candidate_discarded_at,
180+
asc: fragment("CASE WHEN ? = 'highlighted' THEN 0 WHEN ? = 'approved' THEN 1 ELSE 2 END", m.status, m.status),
181+
desc: m.updated_at
177182
)
183+
|> preload(job_posting: :user)
184+
|> Repo.all()
178185
end
179186

180187
# Private helper functions

0 commit comments

Comments
 (0)