Migrates back to datomic on-prem
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require
|
||||
[auto-ap.datomic :refer [audit-transact conn merge-query]]
|
||||
[iol-ion.tx :refer [upsert-entity random-tempid]]
|
||||
[auto-ap.datomic :refer [audit-transact conn merge-query query2]]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.graphql.utils
|
||||
@@ -16,8 +15,9 @@
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.string :as str]
|
||||
[datomic.client.api :as dc]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as dc]
|
||||
[iol-ion.tx :refer [random-tempid]]))
|
||||
|
||||
(defn get-transaction-rule-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -82,7 +82,7 @@
|
||||
rule-id (if id
|
||||
id
|
||||
"transaction-rule")
|
||||
transaction [`(upsert-entity ~#:transaction-rule {:db/id (or rule-id (random-tempid))
|
||||
transaction [[:upsert-entity #:transaction-rule {:db/id (or rule-id (random-tempid))
|
||||
:description description
|
||||
:note note
|
||||
:client client_id
|
||||
@@ -98,7 +98,7 @@
|
||||
name
|
||||
snake->kebab
|
||||
(keyword "transaction-approval-status"))
|
||||
:transaction-rule/accounts (map transaction-rule-account->entity accounts)})]
|
||||
:transaction-rule/accounts (map transaction-rule-account->entity accounts)}]]
|
||||
|
||||
|
||||
transaction-result (audit-transact transaction (:id context))]
|
||||
@@ -108,87 +108,85 @@
|
||||
(->graphql))))
|
||||
|
||||
(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]
|
||||
(->>
|
||||
(dc/q
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
:transaction/bank-account [:bank-account/name]
|
||||
:transaction/payment [:db/id]}
|
||||
])]
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [(dc/db conn)]
|
||||
:timeout 55000}
|
||||
description
|
||||
(merge-query {:query {:in ['?descr]
|
||||
:where ['[(iol-ion.query/->pattern ?descr) ?description-regex]]}
|
||||
:args [description]})
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
:transaction/bank-account [:bank-account/name]
|
||||
:transaction/payment [:db/id]}
|
||||
])]
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [(dc/db conn)]}
|
||||
description
|
||||
(merge-query {:query {:in ['?descr]
|
||||
:where ['[(iol-ion.query/->pattern ?descr) ?description-regex]]}
|
||||
:args [description]})
|
||||
|
||||
(limited-clients id)
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients id)))]})
|
||||
(limited-clients id)
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients id)))]})
|
||||
|
||||
bank-account
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:db/id bank-account)]})
|
||||
bank-account
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:db/id bank-account)]})
|
||||
|
||||
description
|
||||
(merge-query {:query {:where ['[?e :transaction/description-original ?do]
|
||||
'[(re-find ?description-regex ?do)]]}})
|
||||
description
|
||||
(merge-query {:query {:where ['[?e :transaction/description-original ?do]
|
||||
'[(re-find ?description-regex ?do)]]}})
|
||||
|
||||
yodlee-merchant
|
||||
(merge-query {:query {:in ['?yodlee-merchant-id]
|
||||
:where ['[?e :transaction/yodlee-merchant ?yodlee-merchant-id]]}
|
||||
:args [(:db/id yodlee-merchant)]})
|
||||
yodlee-merchant
|
||||
(merge-query {:query {:in ['?yodlee-merchant-id]
|
||||
:where ['[?e :transaction/yodlee-merchant ?yodlee-merchant-id]]}
|
||||
:args [(:db/id yodlee-merchant)]})
|
||||
|
||||
amount-gte
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?ta]
|
||||
'[(>= ?ta ?amount-gte)]]}
|
||||
:args [amount-gte]})
|
||||
amount-gte
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?ta]
|
||||
'[(>= ?ta ?amount-gte)]]}
|
||||
:args [amount-gte]})
|
||||
|
||||
amount-lte
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?ta]
|
||||
'[(<= ?ta ?amount-lte)]]}
|
||||
:args [amount-lte]})
|
||||
amount-lte
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?ta]
|
||||
'[(<= ?ta ?amount-lte)]]}
|
||||
:args [amount-lte]})
|
||||
|
||||
dom-lte
|
||||
(merge-query {:query {:in ['?dom-lte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(<= ?dom ?dom-lte)]]}
|
||||
:args [dom-lte]})
|
||||
dom-lte
|
||||
(merge-query {:query {:in ['?dom-lte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(<= ?dom ?dom-lte)]]}
|
||||
:args [dom-lte]})
|
||||
|
||||
dom-gte
|
||||
(merge-query {:query {:in ['?dom-gte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(>= ?dom ?dom-gte)]]}
|
||||
:args [dom-gte]})
|
||||
dom-gte
|
||||
(merge-query {:query {:in ['?dom-gte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(>= ?dom ?dom-gte)]]}
|
||||
:args [dom-gte]})
|
||||
|
||||
client
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:db/id client)]})
|
||||
client
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:db/id client)]})
|
||||
|
||||
|
||||
(not include-coded?)
|
||||
(merge-query {:query {:where ['[or [?e :transaction/approval-status :transaction-approval-status/unapproved]
|
||||
[(missing? $ ?e :transaction/approval-status)]]]}})
|
||||
(not include-coded?)
|
||||
(merge-query {:query {:where ['[or [?e :transaction/approval-status :transaction-approval-status/unapproved]
|
||||
[(missing? $ ?e :transaction/approval-status)]]]}})
|
||||
|
||||
true
|
||||
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||
|
||||
(transduce (comp
|
||||
(take (or count 15))
|
||||
(map first)
|
||||
(map #(dissoc % :transaction/id))
|
||||
(map (fn [x]
|
||||
(update x :transaction/date c/from-date)))
|
||||
(map ->graphql))
|
||||
conj [])))
|
||||
true
|
||||
(merge-query {:query {:where ['[?e :transaction/id]]}}))]
|
||||
(->>
|
||||
(query2 query)
|
||||
(transduce (comp
|
||||
(take (or count 15))
|
||||
(map first)
|
||||
(map #(dissoc % :transaction/id))
|
||||
(map (fn [x]
|
||||
(update x :transaction/date c/from-date)))
|
||||
(map ->graphql))
|
||||
conj []))))
|
||||
|
||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description client_id bank_account_id amount_lte amount_gte dom_lte dom_gte yodlee_merchant_id]} :transaction_rule} _]
|
||||
(assert-admin id)
|
||||
|
||||
Reference in New Issue
Block a user