A command is an embedded_schema with the board's fields. use Datumo.Command
gives it new/2 and changeset/2: every field is required unless it's named
in optional: (the fields with optional: true on the board).
defmodule MyApp.Slices.RegisterPlot.RegisterPlot do
use Datumo.Command, optional: [:note]
embedded_schema do
field :plot_id, :string
field :name, :string
field :note, :string
end
endnew(params, generated) returns {:ok, cmd} or {:error, changeset}.
generated carries what context.ex creates (ids, instants). A missing field
is an error key — {field, {"can't be blank", [validation: :required]}} —
and the screen turns it into words (translate_error/1, Gettext).
A closed list or a format the field's description states goes in an override that keeps the default:
def changeset(params, generated) do
super(params, generated) |> validate_inclusion(:unit, ~w(kg t))
end