Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/744
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Oct 16, 2023
1 parent 64151cd commit e89d592
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/character.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ defmodule Bonfire.Data.Identity.Character do
@cast [:username]
@required [:username]

def changeset_basic(char, params) do
error(params)

char
|> debug()
|> Changeset.cast(params, @cast)

# |> Changesets.cast_assoc(:actor)
end

def changeset(char \\ %Character{}, params, extra \\ nil)

def changeset(char, params, nil) do
char
|> Changesets.cast(params, @cast)
changeset_basic(char, params)
|> Changeset.validate_required(@required)
|> Changeset.unique_constraint(:username)
|> put_boxes(params)
Expand All @@ -43,7 +52,7 @@ defmodule Bonfire.Data.Identity.Character do
end

def changeset(char, params, :update) do
Changeset.cast(char, params, @cast)
changeset_basic(char, params)
end

def changeset(char, params, :hash) do
Expand All @@ -53,7 +62,7 @@ defmodule Bonfire.Data.Identity.Character do
end

defp put_boxes(changeset, _params) do
if changeset.valid? do
if changeset.valid? and changeset.data.__meta__.state == :built do
# || raise "Character requires an ID to be set on the pointable." # FIXME
id = Pointers.Changesets.get_field(changeset, :id)
# debug(id, "changeset id")
Expand Down

0 comments on commit e89d592

Please sign in to comment.