commit 180d66c6e9c87f22ab7dcb80c9ccaf5d04d992b8
parent c4cea620faa03f3437e28cbe2c31319c8ec287f8
Author: Alberto Lerda <30939098+albertolerda@users.noreply.github.com>
Date: Thu, 17 Nov 2022 13:52:20 +0100
Zenflows.VF.{EconomicResource,Proposal}: add search on note field (#35)
Diffstat:
4 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/zenflows/vf/economic_resource/query.ex b/src/zenflows/vf/economic_resource/query.ex
@@ -57,6 +57,10 @@ defp all_f(q, {:name, v}),
do: where(q, [x], ilike(x.name, ^"%#{v}%"))
defp all_f(q, {:or_name, v}),
do: or_where(q, [x], ilike(x.name, ^"%#{v}%"))
+defp all_f(q, {:note, v}),
+ do: where(q, [x], ilike(x.note, ^"%#{v}%"))
+defp all_f(q, {:or_note, v}),
+ do: or_where(q, [x], ilike(x.note, ^"%#{v}%"))
@spec all_validate(Schema.params()) ::
{:ok, Changeset.data()} | {:error, Changeset.t()}
@@ -74,6 +78,8 @@ defp all_validate(params) do
or_gt_onhand_quantity_has_numerical_value: :float,
name: :string,
or_name: :string,
+ note: :string,
+ or_note: :string,
}}
|> Changeset.cast(params, ~w[
classified_as or_classified_as
@@ -82,7 +88,7 @@ defp all_validate(params) do
conforms_to or_conforms_to
gt_onhand_quantity_has_numerical_value
or_gt_onhand_quantity_has_numerical_value
- name or_name
+ name or_name note or_note
]a)
|> Validate.class(:classified_as)
|> Validate.class(:or_classified_as)
@@ -106,9 +112,14 @@ defp all_validate(params) do
])
|> Validate.name(:name)
|> Validate.name(:or_name)
+ |> Validate.note(:note)
+ |> Validate.note(:or_note)
|> Validate.exist_nand([:name, :or_name])
+ |> Validate.exist_nand([:note, :or_note])
|> Validate.escape_like(:name)
|> Validate.escape_like(:or_name)
+ |> Validate.escape_like(:note)
+ |> Validate.escape_like(:or_note)
|> Changeset.apply_action(nil)
end
diff --git a/src/zenflows/vf/economic_resource/type.ex b/src/zenflows/vf/economic_resource/type.ex
@@ -254,6 +254,8 @@ input_object :economic_resource_filter_params do
field :or_gt_onhand_quantity_has_numerical_value, :float
field :name, :string
field :or_name, :string
+ field :note, :string
+ field :or_note, :string
end
object :query_economic_resource do
diff --git a/src/zenflows/vf/proposal/query.ex b/src/zenflows/vf/proposal/query.ex
@@ -73,6 +73,16 @@ defp all_f(q, {:or_primary_intents_resource_inventoried_as_name, v}) do
|> join(:primary_intents_resource_inventoried_as)
|> or_where([primary_intents_resource_inventoried_as: r], ilike(r.name, ^"%#{v}%"))
end
+defp all_f(q, {:primary_intents_resource_inventoried_as_note, v}) do
+ q
+ |> join(:primary_intents_resource_inventoried_as)
+ |> where([primary_intents_resource_inventoried_as: r], ilike(r.note, ^"%#{v}%"))
+end
+defp all_f(q, {:or_primary_intents_resource_inventoried_as_note, v}) do
+ q
+ |> join(:primary_intents_resource_inventoried_as)
+ |> or_where([primary_intents_resource_inventoried_as: r], ilike(r.note, ^"%#{v}%"))
+end
defp all_f(q, {:primary_intents_resource_inventoried_as_id, v}) do
q
|> join(:primary_intents_resource_inventoried_as)
@@ -112,6 +122,8 @@ defp all_validate(params) do
or_primary_intents_resource_inventoried_as_classified_as: {:array, :string},
primary_intents_resource_inventoried_as_name: :string,
or_primary_intents_resource_inventoried_as_name: :string,
+ primary_intents_resource_inventoried_as_note: :string,
+ or_primary_intents_resource_inventoried_as_note: :string,
primary_intents_resource_inventoried_as_id: {:array, ID},
or_primary_intents_resource_inventoried_as_id: {:array, ID},
}}
@@ -124,6 +136,8 @@ defp all_validate(params) do
or_primary_intents_resource_inventoried_as_classified_as
primary_intents_resource_inventoried_as_name
or_primary_intents_resource_inventoried_as_name
+ primary_intents_resource_inventoried_as_note
+ or_primary_intents_resource_inventoried_as_note
primary_intents_resource_inventoried_as_id
or_primary_intents_resource_inventoried_as_id
]a)
@@ -145,6 +159,12 @@ defp all_validate(params) do
|> Validate.name(:or_primary_intents_resource_inventoried_as_name)
|> Validate.exist_nand([:primary_intents_resource_inventoried_as_name,
:or_primary_intents_resource_inventoried_as_name])
+ |> Validate.escape_like(:primary_intents_resource_inventoried_as_note)
+ |> Validate.escape_like(:or_primary_intents_resource_inventoried)
+ |> Validate.note(:primary_intents_resource_inventoried_as_note)
+ |> Validate.note(:or_primary_intents_resource_inventoried_as_note)
+ |> Validate.exist_nand([:primary_intents_resource_inventoried_as_note,
+ :or_primary_intents_resource_inventoried_as_note])
|> Validate.class(:primary_intents_resource_inventoried_as_id)
|> Validate.class(:or_primary_intents_resource_inventoried_as_id)
|> Validate.exist_nand([:primary_intents_resource_inventoried_as_id,
diff --git a/src/zenflows/vf/proposal/type.ex b/src/zenflows/vf/proposal/type.ex
@@ -139,6 +139,8 @@ input_object :proposal_filter_params do
field :or_primary_intents_resource_inventoried_as_classified_as, list_of(non_null(:uri))
field :primary_intents_resource_inventoried_as_name, :string
field :or_primary_intents_resource_inventoried_as_name, :string
+ field :primary_intents_resource_inventoried_as_note, :string
+ field :or_primary_intents_resource_inventoried_as_note, :string
field :primary_intents_resource_inventoried_as_id, list_of(non_null(:id))
field :or_primary_intents_resource_inventoried_as_id, list_of(non_null(:id))
end