Skip to content

Commit

Permalink
fixup! reduce redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
amaisano committed Jul 11, 2019
1 parent 64c7215 commit 61fd5a6
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions apps/site/lib/site_web/controllers/project_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,15 @@ defmodule SiteWeb.ProjectController do
end

@spec get_events_async(integer, :past | :upcoming) :: (() -> [Teaser.t()])
def get_events_async(id, :past) do
def get_events_async(id, timeframe) do
fn ->
Repo.teasers(
type: :event,
related_to: id,
items_per_page: 10,
date_op: "<",
date_op: (timeframe == :past && "<") || ">=",
date: [value: "now"],
sort_order: "DESC"
)
end
end

def get_events_async(id, :upcoming) do
fn ->
Repo.teasers(
type: :event,
related_to: id,
items_per_page: 10,
date_op: ">=",
date: [value: "now"],
sort_order: "ASC"
sort_order: (timeframe == :past && "DESC") || "ASC"
)
end
end
Expand Down

0 comments on commit 61fd5a6

Please sign in to comment.