2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
module Emails
|
|
|
|
class DestroyService < ::Emails::BaseService
|
2018-03-17 18:26:18 +05:30
|
|
|
def execute(email)
|
2021-11-11 11:23:49 +05:30
|
|
|
email.destroy && update_secondary_emails!(email.email)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def update_secondary_emails!(deleted_email)
|
2018-03-17 18:26:18 +05:30
|
|
|
result = ::Users::UpdateService.new(@current_user, user: @user).execute do |user|
|
2021-11-11 11:23:49 +05:30
|
|
|
user.unset_secondary_emails_matching_deleted_email!(deleted_email)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result[:status] == :success
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Emails::DestroyService.prepend_mod_with('Emails::DestroyService')
|