Skip to content

Instantly share code, notes, and snippets.

@spejman
Last active April 26, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spejman/46ec03360e9f4ae1eeb1cfb593e01cee to your computer and use it in GitHub Desktop.
Save spejman/46ec03360e9f4ae1eeb1cfb593e01cee to your computer and use it in GitHub Desktop.
defmodule BFFWeb.V2.UnreadNotificationsController do
use BFFWeb, :controller
def index(conn, params) do
{conversations_count, offers_pending_count, jobs_pending_count} =
async with {:ok, candidate_id} <- Candidates.get_current_candidate_id(conn.assigns.auth_token),
{:ok, conversations_count} <- Conversations.count_unread_conversations(candidate_id),
{:ok, offers_pending_count} <- Transactions.count_offers_pending(candidate_id),
{:ok, jobs_pending_count} <- Transactions.count_jobs_pending(candidate_id) do
{conversations_count, offers_pending_count, jobs_pending_count}
else
_ -> {-1, -1, -1}
end
conn
|> assign(:unread_conversations_messages_count, conversations_count)
|> assign(:offers_pending_to_action_count, offers_pending_count)
|> assign(:jobs_pending_to_action_count, jobs_pending_count)
|> render("index.json")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment