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