Makes integreat run on datomic cloud
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [audit-transact
|
||||
conn
|
||||
merge-query
|
||||
remove-nils
|
||||
replace-nils-with-retract]]
|
||||
[auto-ap.datomic :refer [audit-transact conn merge-query upsert-entity]]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.graphql.utils
|
||||
@@ -20,7 +15,7 @@
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(defn get-transaction-rule-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -37,10 +32,10 @@
|
||||
nil))
|
||||
|
||||
(defn transaction-rule-account->entity [{:keys [id account_id percentage location]}]
|
||||
(remove-nils #:transaction-rule-account {:percentage percentage
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location}))
|
||||
#:transaction-rule-account {:percentage percentage
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location})
|
||||
|
||||
(defn delete-transaction-rule [context {:keys [transaction_rule_id ]} _]
|
||||
(assert-admin (:id context))
|
||||
@@ -53,8 +48,7 @@
|
||||
|
||||
(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 dom_gte dom_lte]} :transaction_rule} _]
|
||||
(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
||||
(let [account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
||||
_ (try
|
||||
(. java.util.regex.Pattern (compile description java.util.regex.Pattern/CASE_INSENSITIVE))
|
||||
(catch Exception e
|
||||
@@ -67,8 +61,8 @@
|
||||
(let [error (str "You must provide a description or a yodlee merchant")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
_ (doseq [a accounts
|
||||
:let [{:keys [:account/location :account/name]} (d/entity (d/db conn) (:account_id a))
|
||||
client (d/entity (d/db conn) client_id)
|
||||
:let [{:keys [:account/location :account/name]} (dc/pull (dc/db conn) [:account/location :account/name] (:account_id a))
|
||||
client (dc/pull (dc/db conn) [:client/locations] client_id)
|
||||
]]
|
||||
(when (and location (not= location (:location a)))
|
||||
(let [err (str "Account " name " uses location " (:location a) ", but is supposed to be " location)]
|
||||
@@ -82,27 +76,25 @@
|
||||
rule-id (if id
|
||||
id
|
||||
"transaction-rule")
|
||||
transaction (replace-nils-with-retract #:transaction-rule {:db/id rule-id
|
||||
:description description
|
||||
:note note
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:yodlee-merchant yodlee_merchant_id
|
||||
:dom-lte dom_lte
|
||||
:dom-gte dom_gte
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
:transaction-approval-status
|
||||
(some->> transaction_approval_status
|
||||
name
|
||||
snake->kebab
|
||||
(keyword "transaction-approval-status"))}
|
||||
existing-transaction)
|
||||
transaction [`(upsert-entity ~#:transaction-rule {:db/id rule-id
|
||||
:description description
|
||||
:note note
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:yodlee-merchant yodlee_merchant_id
|
||||
:dom-lte dom_lte
|
||||
:dom-gte dom_gte
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
:transaction-approval-status
|
||||
(some->> transaction_approval_status
|
||||
name
|
||||
snake->kebab
|
||||
(keyword "transaction-approval-status"))
|
||||
:transaction-rule/accounts (map transaction-rule-account->entity accounts)})]
|
||||
|
||||
|
||||
transaction (conj transaction
|
||||
[:reset rule-id :transaction-rule/accounts (map transaction-rule-account->entity accounts)])
|
||||
transaction-result (audit-transact transaction (:id context))]
|
||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||
id))
|
||||
@@ -111,14 +103,14 @@
|
||||
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded? count]
|
||||
(->>
|
||||
(d/query
|
||||
(dc/q
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
:transaction/bank-account [:bank-account/name]
|
||||
:transaction/payment [:db/id]}
|
||||
])]
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [(d/db conn)]}
|
||||
:args [(dc/db conn)]}
|
||||
|
||||
(limited-clients id)
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
|
||||
Reference in New Issue
Block a user