supporting transaction automation
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
(def default-read '[*
|
||||
{:transaction-rule/client [:client/name :db/id :client/code]}
|
||||
{:transaction-rule/bank-account [*]}
|
||||
{:transaction-rule/yodlee-merchant [*]}
|
||||
{:transaction-rule/yodlee-merchant [:db/id :yodlee-merchant/name :yodlee-merchant/yodlee-id]}
|
||||
{:transaction-rule/transaction-approval-status [:db/id :db/ident]}
|
||||
{:transaction-rule/vendor [:vendor/name :db/id :vendor/default-account]}
|
||||
{:transaction-rule/accounts [:transaction-rule-account/percentage
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
(defn get-merchants [args]
|
||||
;; TODO admin?
|
||||
(let [query {:query {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id])]
|
||||
(let [query {:query {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id :db/id])]
|
||||
:in ['$]
|
||||
:where [['?e :yodlee-merchant/name]]}
|
||||
:args [(d/db (d/connect uri))]}]
|
||||
|
||||
@@ -539,6 +539,7 @@
|
||||
:note {:type 'String}
|
||||
:bank_account_id {:type :id}
|
||||
:client_id {:type :id}
|
||||
:yodlee_merchant_id {:type :id}
|
||||
:amount_lte {:type :money}
|
||||
:amount_gte {:type :money}
|
||||
:dom_lte {:type 'Int}
|
||||
@@ -851,7 +852,9 @@
|
||||
(catch Exception e
|
||||
(if-let [v (:validation-error (ex-data e))]
|
||||
(println "validation error" v)
|
||||
(println e))
|
||||
(do
|
||||
(.printStackTrace e)
|
||||
(println e )))
|
||||
|
||||
(throw e)))))
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
:account account_id
|
||||
:location location}))
|
||||
;; TODO ASSERT ADMIN
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status ]} :transaction_rule :as z} value]
|
||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status ]} :transaction_rule :as z} value]
|
||||
#_(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
@@ -53,6 +53,7 @@
|
||||
:note note
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:yodlee-merchant yodlee_merchant_id
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
|
||||
@@ -254,5 +254,5 @@
|
||||
(fn [{:keys [db]} _]
|
||||
{:graphql {:token (:user db)
|
||||
:query-obj {:venia/queries [[:yodlee-merchants
|
||||
[:name :yodlee-id]]]}
|
||||
[:name :yodlee-id :id]]]}
|
||||
:on-success [::yodlee-merchants-received]}}))
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
:dom-gte
|
||||
:dom-lte
|
||||
:transaction-approval-status
|
||||
[:yodlee-merchant [:name :id :yodlee-id]]
|
||||
[:vendor [:name :id]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :id]]
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
:accounts
|
||||
:note])
|
||||
(assoc :vendor-id (:id (:vendor data)))
|
||||
(assoc :yodlee-merchant-id (:id (:yodlee-merchant data)))
|
||||
(update :accounts (fn [as]
|
||||
(map #(-> %
|
||||
(update :id (fn [i] (if (some-> i (str/starts-with? "new-"))
|
||||
@@ -118,9 +119,9 @@
|
||||
:dom-gte
|
||||
:vendor
|
||||
:accounts
|
||||
:yodlee-merchant
|
||||
:transaction-approval-status])
|
||||
(update :accounts (fn [xs]
|
||||
(println xs)
|
||||
(mapv #(assoc % :amount-percentage (* (:percentage %) 100.0))
|
||||
xs))))))))
|
||||
|
||||
@@ -219,7 +220,7 @@
|
||||
|
||||
[field "Yodlee Merchant"
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/yodlee-merchants])
|
||||
:match->text #(str (:name %) " - " (:yodlee-id %))
|
||||
:match->text #(do (println %) (str (:name %) " - " (:yodlee-id %)))
|
||||
:type "typeahead-entity"
|
||||
:field [:yodlee-merchant]}]]
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[:vendor [:name :id]]
|
||||
[:accounts [:id :amount :location [:account [:name :id :location :numeric-code]]]]
|
||||
:date
|
||||
[:yodlee_merchant [:name :yodlee-id]]
|
||||
[:yodlee_merchant [:name :yodlee-id :id]]
|
||||
:post_date
|
||||
:status
|
||||
:description_original
|
||||
|
||||
@@ -33,12 +33,14 @@
|
||||
(is (seqable? (:transaction-rules result))))))
|
||||
|
||||
(deftest upsert-transaction-rule
|
||||
(let [{:strs [vendor-id account-id]} (-> (d/connect uri)
|
||||
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (-> (d/connect uri)
|
||||
(d/transact
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}])
|
||||
:db/id "account-id"}
|
||||
{:yodlee-merchant/name "yodlee"
|
||||
:db/id "yodlee-merchant-id"}])
|
||||
deref
|
||||
:tempids)]
|
||||
(testing "it should reject rules that don't add up to 100%"
|
||||
@@ -55,6 +57,7 @@
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||
{:transaction-rule {:description "123"
|
||||
:yodlee-merchant-id yodlee-merchant-id
|
||||
:vendor-id vendor-id
|
||||
:transaction-approval-status :approved
|
||||
:accounts [{:account-id account-id
|
||||
@@ -66,6 +69,7 @@
|
||||
[:id :description
|
||||
:transaction-approval-status
|
||||
[:vendor [:name]]
|
||||
[:yodlee-merchant [:name]]
|
||||
[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||
result (-> (sut/query nil q)
|
||||
:data
|
||||
@@ -73,6 +77,7 @@
|
||||
|
||||
(is (= "123" (:description result)))
|
||||
(is (= "Bryce's Meat Co" (-> result :vendor :name)))
|
||||
(is (= "yodlee" (-> result :yodlee-merchant :name)))
|
||||
(is (= :approved (:transaction-approval-status result)))
|
||||
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
||||
(is (:id result))
|
||||
|
||||
Reference in New Issue
Block a user