Skip to content

Instantly share code, notes, and snippets.

@Ayoush
Created February 24, 2020 18:21
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 Ayoush/ec179bdef1b207b42c9bb62791002cdf to your computer and use it in GitHub Desktop.
Save Ayoush/ec179bdef1b207b42c9bb62791002cdf to your computer and use it in GitHub Desktop.
Enum.reduce(params, dynamic(true), fn
{"workspace_id", workspace_id}, dynamic_query ->
dynamic(
[task, project, user_task, time_track],
^dynamic_query and project.workspace_id == ^workspace_id
)
{"user_ids", user_ids}, dynamic_query ->
user_ids = Enum.map(String.split(user_ids, ","), fn x -> String.to_integer(x) end)
dynamic(
[task, project, user_task, time_track],
^dynamic_query and user_task.user_id in ^user_ids
)
{"project_ids", project_ids}, dynamic_query ->
project_ids = Enum.map(String.split(project_ids, ","), fn x -> String.to_integer(x) end)
dynamic(
[task, project, user_task, time_track],
^dynamic_query and task.project_id in ^project_ids
)
{_, _}, dynamic_query ->
dynamic_query
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment