Skip to content

Commit d034509

Browse files
committed
feat: enhance job match retrieval and deletion logic
1 parent c74bac7 commit d034509

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/algora/matches/matches.ex

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ defmodule Algora.Matches do
4747
|> Enum.concat(job.countries)
4848
|> Enum.uniq()
4949

50+
existing_matches =
51+
Repo.all(
52+
from(m in JobMatch,
53+
where: m.job_posting_id == ^job_posting_id,
54+
where: m.status in [:highlighted, :approved]
55+
)
56+
)
57+
58+
existing_user_ids = Enum.map(existing_matches, & &1.user_id)
59+
5060
[
51-
limit: 3,
61+
limit: 6 - length(existing_matches),
62+
ids_not: existing_user_ids,
5263
tech_stack: job.tech_stack,
5364
has_min_compensation: true,
5465
system_tags: job.system_tags,
@@ -79,7 +90,12 @@ defmodule Algora.Matches do
7990

8091
Repo.transact(fn ->
8192
# Delete existing matches for this job posting
82-
Repo.delete_all(from(m in JobMatch, where: m.job_posting_id == ^job_posting_id))
93+
Repo.delete_all(
94+
from(m in JobMatch,
95+
where: m.job_posting_id == ^job_posting_id,
96+
where: m.status not in [:highlighted, :approved]
97+
)
98+
)
8399

84100
# Insert new matches
85101
case Repo.insert_all(JobMatch, matches, on_conflict: :nothing) do

0 commit comments

Comments
 (0)