# organization.ex
create :create_organization do
argument :establishment, :map
change relate_actor(:owner)
change after_action(fn changeset, org, context ->
# I’m doing this to return establishment validation errors back to the frontend.
# However, I had to change the attribute names (e.g., "name" → "organization_name"/"establishment_name")
# in both Organization and Establishment resources to differentiate them in my Inertia form—otherwise
# it couldn't map the error to the right field.
# Is this the best approach?
case Lamashka.Establishments.create_establishment(
changeset.arguments.establishment,
actor: context.actor,
tenant: org
) do
{:ok, _establishment} -> {:ok, org}
{:error, error} -> {:error, error}
end
end)
end
# establishment.ex
create :create_establishment do
change after_action(fn _changeset, est, context ->
Lamashka.Establishments.add_establishment_user!(
%{user_id: context.actor.id, role: :admin},
tenant: est
)
{:ok, est}
end)
end
# establishment_user.ex
create :add_establishment_user do
accept [:user_id, :role]
end
# organization.ex
create :create_organization do
argument :establishment, :map
change relate_actor(:owner)
change after_action(fn changeset, org, context ->
# I’m doing this to return establishment validation errors back to the frontend.
# However, I had to change the attribute names (e.g., "name" → "organization_name"/"establishment_name")
# in both Organization and Establishment resources to differentiate them in my Inertia form—otherwise
# it couldn't map the error to the right field.
# Is this the best approach?
case Lamashka.Establishments.create_establishment(
changeset.arguments.establishment,
actor: context.actor,
tenant: org
) do
{:ok, _establishment} -> {:ok, org}
{:error, error} -> {:error, error}
end
end)
end
# establishment.ex
create :create_establishment do
change after_action(fn _changeset, est, context ->
Lamashka.Establishments.add_establishment_user!(
%{user_id: context.actor.id, role: :admin},
tenant: est
)
{:ok, est}
end)
end
# establishment_user.ex
create :add_establishment_user do
accept [:user_id, :role]
end