feat: calculate member.email from user.email

This commit is contained in:
Moritz 2025-08-05 16:51:39 +02:00
parent 0be9bb7cea
commit b7f0060358
Signed by: moritz
GPG key ID: 1020A035E5DD0824
5 changed files with 300 additions and 10 deletions

View file

@ -0,0 +1,19 @@
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} when is_binary(user_email) -> user_email
_ -> record.member_email
end
end)
end
end