Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 1954e3e

Browse files
committed
fix(profile): update error when social keys involved
1 parent 5e47c71 commit 1954e3e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/mastani_server/accounts/delegates/profile.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ defmodule MastaniServer.Accounts.Delegate.Profile do
222222

223223
defp update_social_ifneed(changeset, %User{} = user, %{social: attrs}) do
224224
Social |> ORM.upsert_by([user_id: user.id], attrs)
225-
changeset
225+
Ecto.Changeset.put_change(changeset, :social, nil)
226226
end
227227

228228
defp update_social_ifneed(changeset, _user, _attrs), do: changeset

lib/mastani_server/accounts/social.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ defmodule MastaniServer.Accounts.Social do
3838
|> cast(attrs, @optional_fields ++ @required_fields)
3939
|> validate_required(@required_fields)
4040
|> foreign_key_constraint(:user_id)
41+
|> unique_constraint(:user, name: :user_socials_user_id_index)
4142
end
4243

4344
@doc false
4445
def update_changeset(%Social{} = social, attrs) do
4546
social
4647
|> cast(attrs, @optional_fields ++ @required_fields)
4748
|> foreign_key_constraint(:user_id)
49+
|> unique_constraint(:user, name: :user_socials_user_id_index)
4850
end
4951
end

0 commit comments

Comments
 (0)