You can now kind of choose a yodlee merchant
This commit is contained in:
14
src/clj/auto_ap/datomic/yodlee_merchants.clj
Normal file
14
src/clj/auto_ap/datomic/yodlee_merchants.clj
Normal file
@@ -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))))
|
||||
@@ -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
|
||||
|
||||
7
src/clj/auto_ap/graphql/yodlee_merchants.clj
Normal file
7
src/clj/auto_ap/graphql/yodlee_merchants.clj
Normal file
@@ -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))))
|
||||
|
||||
@@ -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]}}))
|
||||
|
||||
@@ -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)))
|
||||
|
||||
@@ -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])]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user