feat: calculate member.email from user.email
This commit is contained in:
parent
0be9bb7cea
commit
b7f0060358
5 changed files with 300 additions and 10 deletions
19
lib/membership/member_email_calculation.ex
Normal file
19
lib/membership/member_email_calculation.ex
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue