Skip to content

Commit

Permalink
Merge pull request #980 from OpenFn/issue968
Browse files Browse the repository at this point in the history
Don't add cast fragments if the search_term is nil
  • Loading branch information
taylordowns2000 authored Jul 27, 2023
2 parents 8919dc3 + e88180d commit 8f162b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to

### Changed

- Don't add cast fragments if the search_term is nil
[#968](https://github.com/OpenFn/Lightning/issues/968)

### Fixed

## [v0.7.0-pre2] - 2023-07-26
Expand Down
56 changes: 29 additions & 27 deletions lib/lightning/invocation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -381,35 +381,37 @@ defmodule Lightning.Invocation do
end)
end

def filter_run_body_and_logs_where(_search_term, search_fields)
when search_fields == [] do
dynamic(true)
end

def filter_run_body_and_logs_where(search_term, search_fields)
when search_fields != [] do
Enum.reduce(search_fields, dynamic(false), fn
:log, query ->
dynamic(
[log_lines: l],
^query or
fragment(
"cast(? as VARCHAR) ilike ?",
l.body,
^"%#{search_term}%"
)
)
def filter_run_body_and_logs_where(search_term, search_fields) do
if is_nil(search_term) do
dynamic(true)
else
Enum.reduce(search_fields || [], dynamic(false), fn
:log, query ->
dynamic(
[log_lines: l],
^query or
fragment(
"cast(? as VARCHAR) ilike ?",
l.body,
^"%#{search_term}%"
)
)

:body, query ->
dynamic(
[input: i],
^query or
fragment("cast(? as VARCHAR) ilike ?", i.body, ^"%#{search_term}%")
)
:body, query ->
dynamic(
[input: i],
^query or
fragment(
"cast(? as VARCHAR) ilike ?",
i.body,
^"%#{search_term}%"
)
)

_, query ->
query
end)
_, query ->
query
end)
end
end

def list_work_orders_for_project_query(
Expand Down

0 comments on commit 8f162b6

Please sign in to comment.