From 0520e2f0f80e2713e61ea4db7a251c6f005d04af Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 9 May 2019 21:44:54 -0700 Subject: [PATCH] Added regex testing --- src/clj/auto_ap/graphql.clj | 3 ++- src/clj/auto_ap/graphql/transaction_rules.clj | 24 +++++++++++++++++-- .../auto_ap/views/pages/admin/rules/form.cljs | 2 +- src/cljs/auto_ap/views/utils.cljs | 5 +++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 1a955574..0c17d499 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -40,7 +40,8 @@ :serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))} :iso_date {:parse (schema/as-conformer #(time/parse % time/iso-date)) :serialize (schema/as-conformer #(time/unparse % time/iso-date))} - :money {:parse (schema/as-conformer #(if (string? %) + :money {:parse (schema/as-conformer #(if (and (string? %) + (not (str/blank? %))) (Double/parseDouble %) %)) :serialize (schema/as-conformer #(if (double? %) diff --git a/src/clj/auto_ap/graphql/transaction_rules.clj b/src/clj/auto_ap/graphql/transaction_rules.clj index 9c3e4090..db83134a 100644 --- a/src/clj/auto_ap/graphql/transaction_rules.clj +++ b/src/clj/auto_ap/graphql/transaction_rules.clj @@ -28,6 +28,9 @@ id)) (->graphql)))) +(defn tr [z x] + (re-find (re-pattern z) x)) + (defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value] (->> (d/query @@ -48,6 +51,24 @@ :where ['[?e :transaction/bank-account ?bank-account-id]]} :args [bank_account_id]}) + description + (merge-query {:query {:in ['?description-regex] + :where ['[?e :transaction/description-original ?do] + '[(re-find ?description-regex ?do)]]} + :args [(re-pattern description)]}) + + amount_gte + (merge-query {:query {:in ['?amount-gte] + :where ['[?e :transaction/amount ?ta] + '[(>= ?ta ?amount-gte)]]} + :args [amount_gte]}) + + amount_lte + (merge-query {:query {:in ['?amount-lte] + :where ['[?e :transaction/amount ?ta] + '[(<= ?ta ?amount-lte)]]} + :args [amount_lte]}) + client_id (merge-query {:query {:in ['?client-id] :where ['[?e :transaction/client ?client-id]]} @@ -60,5 +81,4 @@ (map (fn [x] (update x :transaction/date c/from-date))) (map ->graphql)) - conj - []))) + conj []))) diff --git a/src/cljs/auto_ap/views/pages/admin/rules/form.cljs b/src/cljs/auto_ap/views/pages/admin/rules/form.cljs index 38d0b615..79fdbe68 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules/form.cljs @@ -173,7 +173,7 @@ :field [:bank-account] :spec ::entity/bank-account}]] - [field "Description" + [field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ] [:input.input {:type "text" :field [:description] :spec ::entity/description}]] diff --git a/src/cljs/auto_ap/views/utils.cljs b/src/cljs/auto_ap/views/utils.cljs index 7758cf30..88e992b1 100644 --- a/src/cljs/auto_ap/views/utils.cljs +++ b/src/cljs/auto_ap/views/utils.cljs @@ -200,7 +200,10 @@ (.preventDefault e) (re-frame/dispatch (-> event (conj field) - (conj (js/parseFloat (.. e -target -value)))))) + (conj (let [val (.. e -target -value)] + (if (and val (not (str/blank? val))) + (js/parseFloat val) + val)))))) :value (get-in subscription field) :class (str class