27 lines
634 B
Elixir
27 lines
634 B
Elixir
defmodule Mv.Membership.MemberEmailCalculation do
|
|
use Ash.Resource.Calculation
|
|
|
|
@impl true
|
|
def load(_query, _opts, _context) do
|
|
# We need member_email and user.email
|
|
[:member_email, user: [:email]]
|
|
end
|
|
|
|
@impl true
|
|
def calculate(records, _opts, _context) do
|
|
Enum.map(records, fn record ->
|
|
case record.user do
|
|
%{email: user_email} ->
|
|
# Convert Ash.CiString to string if needed
|
|
if is_struct(user_email, Ash.CiString) do
|
|
to_string(user_email)
|
|
else
|
|
user_email
|
|
end
|
|
|
|
_ ->
|
|
record.member_email
|
|
end
|
|
end)
|
|
end
|
|
end
|