Skip to content

Commit

Permalink
Add specs to emails context, clean up another dialyzer error
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Dec 22, 2017
1 parent bfa983e commit 997479b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
39 changes: 30 additions & 9 deletions lib/code_corps/emails/emails.ex
Original file line number Diff line number Diff line change
@@ -1,54 +1,75 @@
defmodule CodeCorps.Emails do
alias CodeCorps.Emails.{API, Tasks, Transmissions}
alias CodeCorps.{
Conversation,
ConversationPart,
Emails.API,
Emails.Tasks,
Emails.Transmissions,
Message,
OrganizationInvite,
Project,
ProjectUser,
StripeConnectCharge,
User
}

defdelegate create_templates, to: Tasks
defdelegate update_templates, to: Tasks

@spec send_forgot_password_email(User.t, String.t) :: API.transmission_result
def send_forgot_password_email(user, token) do
user |> Transmissions.ForgotPassword.build(token) |> API.send_transmission
end

def send_message_initiated_by_project_email(message, conversation) do
@spec send_message_initiated_by_project_email(Message.t, Conversation.t) :: API.transmission_result
def send_message_initiated_by_project_email(%Message{} = message, %Conversation{} = conversation) do
message
|> Transmissions.MessageInitiatedByProject.build(conversation)
|> API.send_transmission
end

def send_organization_invite_email(invite) do
@spec send_organization_invite_email(OrganizationInvite.t) :: API.transmission_result
def send_organization_invite_email(%OrganizationInvite{} = invite) do
invite |> Transmissions.OrganizationInvite.build |> API.send_transmission
end

def send_project_approval_request_email(project) do
@spec send_project_approval_request_email(Project.t) :: API.transmission_result
def send_project_approval_request_email(%Project{} = project) do
project
|> Transmissions.ProjectApprovalRequest.build
|> API.send_transmission
end

def send_project_approved_email(project) do
@spec send_project_approved_email(Project.t) :: API.transmission_result
def send_project_approved_email(%Project{} = project) do
project |> Transmissions.ProjectApproved.build |> API.send_transmission
end

def send_project_user_acceptance_email(project_user) do
@spec send_project_user_acceptance_email(ProjectUser.t) :: API.transmission_result
def send_project_user_acceptance_email(%ProjectUser{} = project_user) do
project_user
|> Transmissions.ProjectUserAcceptance.build
|> API.send_transmission
end

def send_project_user_request_email(project_user) do
@spec send_project_user_request_email(ProjectUser.t) :: API.transmission_result
def send_project_user_request_email(%ProjectUser{} = project_user) do
project_user
|> Transmissions.ProjectUserRequest.build
|> API.send_transmission
end

def send_receipt_email(charge, invoice) do
@spec send_receipt_email(StripeConnectCharge.t, Stripe.Invoice.t) :: API.transmission_result
def send_receipt_email(%StripeConnectCharge{} = charge, %Stripe.Invoice{} = invoice) do
case charge |> Transmissions.Receipt.build(invoice) do
%SparkPost.Transmission{} = transmission ->
transmission |> API.send_transmission
{:error, reason} -> {:error, reason}
end
end

def send_reply_to_conversation_email(part, user) do
@spec send_reply_to_conversation_email(ConversationPart.t, User.t) :: API.transmission_result
def send_reply_to_conversation_email(%ConversationPart{} = part, %User{} = user) do
part
|> Transmissions.ReplyToConversation.build(user)
|> API.send_transmission
Expand Down
4 changes: 2 additions & 2 deletions lib/code_corps/messages/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule CodeCorps.Messages do
@doc ~S"""
Gets a `CodeCorps.Conversation` record
"""
@spec get_conversation(integer) :: Conversation.t
@spec get_conversation(integer) :: Conversation.t | nil
def get_conversation(id) do
Conversation |> Repo.get(id)
end
Expand All @@ -59,7 +59,7 @@ defmodule CodeCorps.Messages do
@doc ~S"""
Gets a `CodeCorps.ConversationPart` record
"""
@spec get_part(integer) :: Conversation.t
@spec get_part(integer) :: ConversationPart.t | nil
def get_part(id) do
ConversationPart |> Repo.get(id)
end
Expand Down

0 comments on commit 997479b

Please sign in to comment.