diff --git a/src/clj/auto_ap/datomic/yodlee_merchants.clj b/src/clj/auto_ap/datomic/yodlee_merchants.clj new file mode 100644 index 00000000..14320ff4 --- /dev/null +++ b/src/clj/auto_ap/datomic/yodlee_merchants.clj @@ -0,0 +1,14 @@ +(ns auto-ap.datomic.yodlee-merchants + (:require [datomic.api :as d] + [auto-ap.graphql.utils :refer [->graphql]] + [auto-ap.datomic :refer [uri merge-query]])) + +(defn get-merchants [args] + ;; TODO admin? + (let [query {:query {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id])] + :in ['$] + :where [['?e :yodlee-merchant/name]]} + :args [(d/db (d/connect uri))]}] + (->> + (d/query query) + (mapv first)))) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 80f7460a..49546c8c 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -17,6 +17,7 @@ [auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.vendors :as d-vendors] [auto-ap.graphql.users :as gq-users] + [auto-ap.graphql.yodlee-merchants :as ym] [auto-ap.graphql.ledger :as gq-ledger] [auto-ap.graphql.accounts :as gq-accounts] [auto-ap.graphql.clients :as gq-clients] @@ -371,6 +372,10 @@ :statuses {:type '(list String)}} :resolve :get-all-payments} + :yodlee_merchants {:type '(list :yodlee_merchant) + :args {} + :resolve :get-yodlee-merchants} + :transaction_page {:type '(list :transaction_page) :args {:client_id {:type :id} :bank_account_id {:type :id} @@ -783,6 +788,7 @@ :get-transaction-rule-page gq-transaction-rules/get-transaction-rule-page :get-expense-account-stats get-expense-account-stats :get-invoice-stats get-invoice-stats + :get-yodlee-merchants ym/get-yodlee-merchants :get-client gq-clients/get-client :get-user get-user diff --git a/src/clj/auto_ap/graphql/yodlee_merchants.clj b/src/clj/auto_ap/graphql/yodlee_merchants.clj new file mode 100644 index 00000000..2b2c8cd8 --- /dev/null +++ b/src/clj/auto_ap/graphql/yodlee_merchants.clj @@ -0,0 +1,7 @@ +(ns auto-ap.graphql.yodlee-merchants + (:require [auto-ap.graphql.utils :refer [->graphql <-graphql]] + [auto-ap.datomic.yodlee-merchants :as d-yodlee-merchants])) + +(defn get-yodlee-merchants [context args value] + (->graphql (d-yodlee-merchants/get-merchants (<-graphql args)))) + diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index e4e6ca99..7b58d979 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -242,3 +242,17 @@ (println "Page failure" result) (assoc db :page-failure result :status nil))) + + +(re-frame/reg-event-db + ::yodlee-merchants-received + (fn [db [_ data]] + (assoc db :yodlee-merchants (:yodlee-merchants data)))) + +(re-frame/reg-event-fx + ::yodlee-merchants-needed + (fn [{:keys [db]} _] + {:graphql {:token (:user db) + :query-obj {:venia/queries [[:yodlee-merchants + [:name :yodlee-id]]]} + :on-success [::yodlee-merchants-received]}})) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index c9536eb9..8f513384 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -202,3 +202,8 @@ (if (= 500 (:status error)) "System error occured. If you are stuck, please notify ben@integreatconsult.com." (:message error))))) + +(re-frame/reg-sub + ::yodlee-merchants + (fn [db] + (:yodlee-merchants db))) diff --git a/src/cljs/auto_ap/views/pages/admin/rules.cljs b/src/cljs/auto_ap/views/pages/admin/rules.cljs index 4615f828..3eeca8ad 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules.cljs @@ -7,6 +7,7 @@ [auto-ap.views.pages.admin.rules.form :as form] [auto-ap.views.pages.admin.rules.common :refer [default-read]] [auto-ap.views.utils :refer [dispatch-event with-user]] + [auto-ap.events :as events] [auto-ap.utils :refer [replace-by]] [re-frame.core :as re-frame])) @@ -99,7 +100,8 @@ :on-params-change (fn [params] (re-frame/dispatch [::params-change params]))}] ])) - {:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) })) + {:component-will-mount #(do (re-frame/dispatch-sync [::params-change {}]) + (re-frame/dispatch [::events/yodlee-merchants-needed])) })) (defn admin-rules-page [] (let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::form/form])] 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 8688c102..8df8aaef 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules/form.cljs @@ -217,6 +217,12 @@ :field [:bank-account] :spec ::entity/bank-account}]] + [field "Yodlee Merchant" + [typeahead-entity {:matches @(re-frame/subscribe [::subs/yodlee-merchants]) + :match->text #(str (:name %) " - " (:yodlee-id %)) + :type "typeahead-entity" + :field [:yodlee-merchant]}]] + [field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ] [:input.input {:type "text" :field [:description] diff --git a/test/clj/auto_ap/graphql.clj b/test/clj/auto_ap/graphql.clj index 449894b4..59170cdf 100644 --- a/test/clj/auto_ap/graphql.clj +++ b/test/clj/auto_ap/graphql.clj @@ -94,6 +94,23 @@ (is (= 1 (count (:accounts result)))))))))) +(deftest test-get-yodlee-merchants + (testing "it should find yodlee merchants" + @(d/transact (d/connect uri) + [{:yodlee-merchant/name "Merchant 1" + :yodlee-merchant/yodlee-id "123"} + {:yodlee-merchant/name "Merchant 2" + :yodlee-merchant/yodlee-id "456"}]) + + (is (= [{:name "Merchant 1" :yodlee-id "123"} {:name "Merchant 2" :yodlee-id "456"}] + (-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query + :operation/name "GetYodleeMerchants"} + :venia/queries [{:query/data (sut/->graphql [:yodlee-merchants + [:yodlee-id :name]])}]})) + :data + :yodlee-merchants))))) + + (deftest test-transaction-rule (testing "it should match rules" (let [matching-transaction @(d/transact (d/connect uri)