Skip to content

Commit 06946d6

Browse files
committed
notify on match
1 parent 8385f22 commit 06946d6

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/algora/cloud.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ defmodule Algora.Cloud do
4545
call(AlgoraCloud.Talent.Jobs.SendJobMatchEmail, :send, [attrs])
4646
end
4747

48+
def notify_candidate_like(attrs) do
49+
call(AlgoraCloud.Talent.Jobs.SendCandidateLikeEmail, :send, [attrs])
50+
end
51+
52+
def notify_company_like(attrs) do
53+
call(AlgoraCloud.Talent.Jobs.SendCompanyLikeEmail, :send, [attrs])
54+
end
55+
4856
def start do
4957
call(AlgoraCloud, :start, [])
5058
end

lib/algora/matches/matches.ex

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,33 @@ defmodule Algora.Matches do
180180
end
181181

182182
def update_job_match(%JobMatch{} = job_match, attrs) do
183-
job_match
184-
|> JobMatch.changeset(attrs)
185-
|> Repo.update()
183+
changeset = JobMatch.changeset(job_match, attrs)
184+
185+
case Repo.update(changeset) do
186+
{:ok, updated_job_match} ->
187+
# Check if approval timestamps were just set and enqueue emails
188+
enqueue_like_emails_if_needed(job_match, updated_job_match)
189+
{:ok, updated_job_match}
190+
191+
error ->
192+
error
193+
end
194+
end
195+
196+
defp enqueue_like_emails_if_needed(old_match, new_match) do
197+
# Check if company_approved_at was just set (wasn't set before, but is now)
198+
if is_nil(old_match.company_approved_at) &&
199+
is_nil(old_match.candidate_approved_at) &&
200+
not is_nil(new_match.company_approved_at) do
201+
Algora.Cloud.notify_company_like(new_match.id)
202+
end
203+
204+
# Check if candidate_approved_at was just set (wasn't set before, but is now)
205+
if is_nil(old_match.candidate_approved_at) &&
206+
is_nil(old_match.company_approved_at) &&
207+
not is_nil(new_match.candidate_approved_at) do
208+
Algora.Cloud.notify_candidate_like(new_match.id)
209+
end
186210
end
187211

188212
def update_job_match_status(match_id, status) do

0 commit comments

Comments
 (0)