Skip to content

Commit 8385f22

Browse files
committed
update match notif logic
1 parent af3cefd commit 8385f22

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/algora/cloud.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ defmodule Algora.Cloud do
4141
call(AlgoraCloud.JobLive, :offer, [assigns])
4242
end
4343

44+
def notify_match(attrs) do
45+
call(AlgoraCloud.Talent.Jobs.SendJobMatchEmail, :send, [attrs])
46+
end
47+
4448
def start do
4549
call(AlgoraCloud, :start, [])
4650
end

lib/algora/matches/matches.ex

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,32 @@ defmodule Algora.Matches do
5252
def upsert_job_match(attrs) do
5353
case create_job_match(attrs) do
5454
{:ok, match} ->
55-
# Admin.enqueue_job_match_emails(1, user_id: attrs.user_id)
55+
if confirmed?(match) do
56+
Algora.Cloud.notify_match(attrs)
57+
end
58+
5659
{:ok, match}
5760

5861
{:error, _changeset} ->
59-
JobMatch
60-
|> Repo.get_by(user_id: attrs.user_id, job_posting_id: attrs.job_posting_id)
61-
|> change(%{status: attrs.status})
62-
|> Repo.update()
62+
match = Repo.get_by(JobMatch, user_id: attrs.user_id, job_posting_id: attrs.job_posting_id)
63+
64+
case match |> change(%{status: attrs.status}) |> Repo.update() do
65+
{:ok, updated_match} = result ->
66+
if not confirmed?(match) and confirmed?(updated_match) do
67+
Algora.Cloud.notify_match(attrs)
68+
end
69+
70+
result
71+
72+
error ->
73+
error
74+
end
6375
end
6476
end
6577

78+
defp confirmed?(%{status: status}) when status in [:approved, :highlighted], do: true
79+
defp confirmed?(_match), do: false
80+
6681
def fetch_job_matches(job_posting_id) do
6782
job = Repo.get!(JobPosting, job_posting_id)
6883

0 commit comments

Comments
 (0)