Skip to content

Commit

Permalink
Fix message queries
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Dec 19, 2017
1 parent 8d55213 commit a52dcc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/code_corps/messages/conversation_query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ defmodule CodeCorps.Messages.ConversationQuery do
end
def project_filter(queryable, %{}), do: queryable

@doc ~S"""
Narrows down a `CodeCorps.Conversation` query by `user_id`, if specified in a
params map
"""
@spec user_filter(Queryable.t, map) :: Queryable.t
def user_filter(queryable, %{"user_id" => user_id}) do
queryable
|> where([c], c.user_id == ^user_id)
end
def user_filter(queryable, %{}), do: queryable


@doc ~S"""
Narrows down a `CodeCorps.Conversation` query to return only those records
Expand Down
1 change: 1 addition & 0 deletions lib/code_corps/messages/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule CodeCorps.Messages do
scope
|> Messages.ConversationQuery.project_filter(params)
|> Messages.ConversationQuery.status_filter(params)
|> Messages.ConversationQuery.user_filter(params)
|> Repo.all()
end

Expand Down
4 changes: 2 additions & 2 deletions priv/repo/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 10.0
-- Dumped by pg_dump version 10.0
-- Dumped from database version 10.1
-- Dumped by pg_dump version 10.1

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down

0 comments on commit a52dcc1

Please sign in to comment.