Sha256: 57c34af62023320bfff041c29d244bfa4c995bc5d7270e009572a7e5cb02eef1
Contents?: true
Size: 1.72 KB
Versions: 7
Compression:
Stored size: 1.72 KB
Contents
require "monban/core" require "monban/use_case/base" require "getto/params" module Monban module UseCase module Account module Change class Email < Base initialize_with( error: Monban::Core::ERRORS, time: [:now], repository: [ :transaction, :account_exists?, :reset_password_email_account, :update_reset_password_email, :reset_password_email, ], ) 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 end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems