generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd46ecc
commit 0c7be19
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Agents | ||
class CreateAgent | ||
include Wisper::Publisher | ||
|
||
def call(support_agent_details:) | ||
# Reuse any existing agent for the e-mail address supplied as login only uses the first one it finds; newer ones are ignored | ||
existing_agent = Support::Agent.find_by(email: support_agent_details.slice(:email, :first_name, :last_name)[:email]) | ||
if existing_agent | ||
existing_agent | ||
else | ||
agent = Support::Agent.create!(support_agent_details.slice(:email, :first_name, :last_name)) | ||
broadcast(:agent_created, agent.id) | ||
agent | ||
end | ||
end | ||
end | ||
end |