Skip to content

Commit 9396519

Browse files
committed
add upsert variant
1 parent 8e93684 commit 9396519

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/algora/matches/matches.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
defmodule Algora.Matches do
22
@moduledoc false
33

4+
import Ecto.Changeset
45
import Ecto.Query, warn: false
56

67
alias Algora.Jobs.JobPosting
78
alias Algora.Matches.JobMatch
89
alias Algora.Repo
910

11+
require Logger
12+
1013
def list_job_matches(opts \\ []) do
1114
order_by_clause = opts[:order_by] || [asc: :updated_at]
1215

@@ -46,6 +49,20 @@ defmodule Algora.Matches do
4649
|> Repo.insert()
4750
end
4851

52+
def upsert_job_match(attrs) do
53+
case create_job_match(attrs) do
54+
{:ok, match} ->
55+
Admin.enqueue_job_match_emails(1, user_id: attrs.user_id)
56+
{:ok, match}
57+
58+
{: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()
63+
end
64+
end
65+
4966
def fetch_job_matches(job_posting_id) do
5067
job = Repo.get!(JobPosting, job_posting_id)
5168

0 commit comments

Comments
 (0)