Commit 76c555a0 authored by James Lopez's avatar James Lopez

update emails service

parent 4b26ed8a
...@@ -155,7 +155,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -155,7 +155,7 @@ class Admin::UsersController < Admin::ApplicationController
def remove_email def remove_email
email = user.emails.find(params[:email_id]) email = user.emails.find(params[:email_id])
success = Emails::DestroyService.new(current_user, user, email: email.email).execute success = Emails::DestroyService.new(current_user, user: user, email: email.email).execute
respond_to do |format| respond_to do |format|
if success if success
......
...@@ -5,7 +5,7 @@ class Profiles::EmailsController < Profiles::ApplicationController ...@@ -5,7 +5,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
end end
def create def create
@email = Emails::CreateService.new(current_user, current_user, email_params).execute @email = Emails::CreateService.new(current_user, email_params.merge(user: current_user)).execute
if @email.errors.blank? if @email.errors.blank?
NotificationService.new.new_email(@email) NotificationService.new.new_email(@email)
...@@ -19,7 +19,7 @@ class Profiles::EmailsController < Profiles::ApplicationController ...@@ -19,7 +19,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def destroy def destroy
@email = current_user.emails.find(params[:id]) @email = current_user.emails.find(params[:id])
Emails::DestroyService.new(current_user, current_user, email: @email.email).execute Emails::DestroyService.new(current_user, user: current_user, email: @email.email).execute
respond_to do |format| respond_to do |format|
format.html { redirect_to profile_emails_url, status: 302 } format.html { redirect_to profile_emails_url, status: 302 }
......
...@@ -545,8 +545,8 @@ class User < ActiveRecord::Base ...@@ -545,8 +545,8 @@ class User < ActiveRecord::Base
def update_emails_with_primary_email def update_emails_with_primary_email
primary_email_record = emails.find_by(email: email) primary_email_record = emails.find_by(email: email)
if primary_email_record if primary_email_record
Emails::DestroyService.new(self, self, email: email).execute Emails::DestroyService.new(self, user: self, email: email).execute
Emails::CreateService.new(self, self, email: email_was).execute Emails::CreateService.new(self, user: self, email: email_was).execute
end end
end end
......
module Emails module Emails
class BaseService class BaseService
def initialize(current_user, user, opts) def initialize(current_user, opts)
@current_user = current_user @current_user = current_user
@user = user @user = opts.delete(:user)
@email = opts[:email] @email = opts[:email]
end end
end end
......
...@@ -332,7 +332,7 @@ module API ...@@ -332,7 +332,7 @@ module API
user = User.find_by(id: params.delete(:id)) user = User.find_by(id: params.delete(:id))
not_found!('User') unless user not_found!('User') unless user
email = Emails::CreateService.new(current_user, user, declared_params(include_missing: false)).execute email = Emails::CreateService.new(current_user, declared_params(include_missing: false).merge(user: user)).execute
if email.errors.blank? if email.errors.blank?
NotificationService.new.new_email(email) NotificationService.new.new_email(email)
...@@ -373,7 +373,7 @@ module API ...@@ -373,7 +373,7 @@ module API
not_found!('Email') unless email not_found!('Email') unless email
destroy_conditionally!(email) do |email| destroy_conditionally!(email) do |email|
Emails::DestroyService.new(current_user, user, email: email.email).execute Emails::DestroyService.new(current_user, user: user, email: email.email).execute
end end
user.update_secondary_emails! user.update_secondary_emails!
...@@ -678,7 +678,7 @@ module API ...@@ -678,7 +678,7 @@ module API
requires :email, type: String, desc: 'The new email' requires :email, type: String, desc: 'The new email'
end end
post "emails" do post "emails" do
email = Emails::CreateService.new(current_user, current_user, declared_params).execute email = Emails::CreateService.new(current_user, declared_params.merge(user: current_user)).execute
if email.errors.blank? if email.errors.blank?
NotificationService.new.new_email(email) NotificationService.new.new_email(email)
...@@ -697,7 +697,7 @@ module API ...@@ -697,7 +697,7 @@ module API
not_found!('Email') unless email not_found!('Email') unless email
destroy_conditionally!(email) do |email| destroy_conditionally!(email) do |email|
Emails::DestroyService.new(current_user, current_user, email: email.email).execute Emails::DestroyService.new(current_user, user: current_user, email: email.email).execute
end end
current_user.update_secondary_emails! current_user.update_secondary_emails!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment