commit f09244deaca0b11f5bf049eb29ea5bec65fede65
parent 49d2e29f2f97655089705e14f1fb564ac3f44d3a
Author: srfsh <dev@srf.sh>
Date: Tue, 15 Nov 2022 01:52:52 +0300
Zenflows.VF.EconomicResource.{Query,Type}: add more filters
Requested by Ennio
Diffstat:
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/src/zenflows/vf/economic_resource/query.ex b/src/zenflows/vf/economic_resource/query.ex
@@ -35,35 +35,80 @@ end
@spec all_f(Queryable.t(), {atom(), term()}) :: Queryable.t()
defp all_f(q, {:classified_as, v}),
do: where(q, [x], fragment("? @> ?", x.classified_as, ^v))
+defp all_f(q, {:or_classified_as, v}),
+ do: or_where(q, [x], fragment("? @> ?", x.classified_as, ^v))
defp all_f(q, {:primary_accountable, v}),
do: where(q, [x], x.primary_accountable_id in ^v)
+defp all_f(q, {:or_primary_accountable, v}),
+ do: or_where(q, [x], x.primary_accountable_id in ^v)
defp all_f(q, {:custodian, v}),
do: where(q, [x], x.custodian_id in ^v)
+defp all_f(q, {:or_custodian, v}),
+ do: or_where(q, [x], x.custodian_id in ^v)
defp all_f(q, {:conforms_to, v}),
do: where(q, [x], x.conforms_to_id in ^v)
+defp all_f(q, {:or_conforms_to, v}),
+ do: or_where(q, [x], x.conforms_to_id in ^v)
defp all_f(q, {:gt_onhand_quantity_has_numerical_value, v}),
do: where(q, [x], x.onhand_quantity_has_numerical_value > ^v)
+defp all_f(q, {:or_gt_onhand_quantity_has_numerical_value, v}),
+ do: or_where(q, [x], x.onhand_quantity_has_numerical_value > ^v)
+defp all_f(q, {:name, v}),
+ do: where(q, [x], ilike(x.name, ^v))
+defp all_f(q, {:namen, v}),
+ do: or_where(q, [x], ilike(x.name, ^v))
@spec all_validate(Schema.params()) ::
{:ok, Changeset.data()} | {:error, Changeset.t()}
defp all_validate(params) do
{%{}, %{
classified_as: {:array, :string},
+ or_classified_as: {:array, :string},
primary_accountable: {:array, ID},
+ or_primary_accountable: {:array, ID},
custodian: {:array, ID},
+ or_custodian: {:array, ID},
conforms_to: {:array, ID},
+ or_conforms_to: {:array, ID},
gt_onhand_quantity_has_numerical_value: :float,
+ or_gt_onhand_quantity_has_numerical_value: :float,
+ name: :string,
+ or_name: :string,
}}
|> Changeset.cast(params, ~w[
- classified_as primary_accountable custodian conforms_to
+ classified_as or_classified_as
+ primary_accountable or_primary_accountable
+ custodian or_custodian
+ conforms_to or_conforms_to
gt_onhand_quantity_has_numerical_value
+ or_gt_onhand_quantity_has_numerical_value
+ name or_name
]a)
|> Validate.class(:classified_as)
+ |> Validate.class(:or_classified_as)
+ |> Validate.exist_nand([:classified_as, :or_classified_as])
|> Validate.class(:primary_accountable)
+ |> Validate.class(:or_primary_accountable)
+ |> Validate.exist_nand([:primary_accountable, :or_primary_accountable])
|> Validate.class(:custodian)
+ |> Validate.class(:or_custodian)
+ |> Validate.exist_nand([:custodian, :or_custodian])
|> Validate.class(:conforms_to)
+ |> Validate.class(:or_conforms_to)
+ |> Validate.exist_nand([:conforms_to, :or_conforms_to])
|> Changeset.validate_number(:gt_onhand_quantity_has_numerical_value,
greater_than_or_equal_to: 0)
+ |> Changeset.validate_number(:or_gt_onhand_quantity_has_numerical_value,
+ greater_than_or_equal_to: 0)
+ |> Validate.exist_nand([
+ :gt_onhand_quantity_has_numerical_value,
+ :or_gt_onhand_quantity_has_numerical_value,
+ ])
+ |> Validate.name(:name)
+ |> Validate.name(:or_name)
+ |> Validate.exist_nand([:name, :or_name])
+ |> Validate.escape_like(:name)
+ |> Validate.escape_like(:or_name)
|> Changeset.apply_action(nil)
end
diff --git a/src/zenflows/vf/economic_resource/type.ex b/src/zenflows/vf/economic_resource/type.ex
@@ -243,10 +243,17 @@ end
input_object :economic_resource_filter_params do
field :classified_as, list_of(non_null(:uri))
+ field :or_classified_as, list_of(non_null(:uri))
field :conforms_to, list_of(non_null(:id))
+ field :or_conforms_to, list_of(non_null(:id))
field :primary_accountable, list_of(non_null(:id))
+ field :or_primary_accountable, list_of(non_null(:id))
field :custodian, list_of(non_null(:id))
+ field :or_custodian, list_of(non_null(:id))
field :gt_onhand_quantity_has_numerical_value, :float
+ field :or_gt_onhand_quantity_has_numerical_value, :float
+ field :name, list_of(non_null(:string))
+ field :or_name, list_of(non_null(:string))
end
object :query_economic_resource do