24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/monban/use_case/account/change/email.rb', line 24
def change(params)
Getto::Params.new.validate(params) do |v|
v.hash(
account_id: v.integer {|val| param_error!(account_id: val) },
email: v.combine([v.string]){|val| param_error!(email: val) },
)
end or param_error!(params: params)
repository.transaction do
unless repository.account_exists?(account_id: params[:account_id])
error.not_found! "account_id: #{params[:account_id]}"
end
email_account = repository.reset_password_email_account(email: params[:email])
if email_account && email_account != params[:account_id]
error.conflict! "email: #{params[:email]}"
end
unless email_account
repository.update_reset_password_email(
account_id: params[:account_id],
email: params[:email],
now: time.now,
)
end
{
email: repository.reset_password_email(account_id: params[:account_id]),
}
end
end
|