making transactions usable.
This commit is contained in:
@@ -4,6 +4,14 @@
|
|||||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||||
[clj-time.coerce :as c]))
|
[clj-time.coerce :as c]))
|
||||||
|
|
||||||
|
(defn sort-fn [args]
|
||||||
|
(cond
|
||||||
|
(= "client" (:sort-by args))
|
||||||
|
#(-> % :transaction/client :client/name)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(keyword "transaction" (:sort-by args))))
|
||||||
|
|
||||||
(defn add-arg [query name value where & rest]
|
(defn add-arg [query name value where & rest]
|
||||||
(let [query (-> query
|
(let [query (-> query
|
||||||
(update :args conj value)
|
(update :args conj value)
|
||||||
@@ -11,11 +19,23 @@
|
|||||||
(update-in [:query :where] conj where))]
|
(update-in [:query :where] conj where))]
|
||||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||||
|
|
||||||
|
(defn apply-sort [args results ]
|
||||||
|
(cond->> results
|
||||||
|
(:sort-by args) (sort-by (sort-fn args))
|
||||||
|
(= (:asc args) false) (reverse)))
|
||||||
|
|
||||||
(defn raw-graphql [args]
|
(defn apply-pagination [args results]
|
||||||
|
(->> results
|
||||||
|
(drop (:start args 0))
|
||||||
|
(take (:count args 100))))
|
||||||
|
|
||||||
|
(defn raw-graphql-ids [args]
|
||||||
(->> (d/query
|
(->> (d/query
|
||||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name :db/id]
|
(cond-> {:query {:find [['pull '?e (into [:db/id] (condp = (:sort-by args)
|
||||||
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}])]
|
"client" [{:transaction/client [:client/name]}]
|
||||||
|
nil []
|
||||||
|
[(keyword "transaction" (:sort-by args))]))
|
||||||
|
]]
|
||||||
:in ['$]
|
:in ['$]
|
||||||
:where ['[?e :transaction/id]]}
|
:where ['[?e :transaction/id]]}
|
||||||
:args [(d/db (d/connect uri))]}
|
:args [(d/db (d/connect uri))]}
|
||||||
@@ -28,27 +48,38 @@
|
|||||||
'[?e :transaction/client ?c]
|
'[?e :transaction/client ?c]
|
||||||
'[?c :client/original-id ?original-id])))
|
'[?c :client/original-id ?original-id])))
|
||||||
(map first)
|
(map first)
|
||||||
|
(map #(update % :transaction/date c/from-date))
|
||||||
|
(map #(update % :transaction/post-date c/from-date))))
|
||||||
|
|
||||||
|
(defn graphql-results [ids args]
|
||||||
|
(->> (d/query
|
||||||
|
(cond-> {:query {:find ['(pull ?xx [* {:transaction/client [:client/name :db/id]
|
||||||
|
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}])]
|
||||||
|
:in ['$]
|
||||||
|
:where []}
|
||||||
|
:args [(d/db (d/connect uri))]}
|
||||||
|
|
||||||
|
true (add-arg '[?xx ...] (set (map :db/id ids))
|
||||||
|
'[?xx])))
|
||||||
|
(map first)
|
||||||
|
|
||||||
(map #(update % :transaction/date c/from-date))
|
(map #(update % :transaction/date c/from-date))
|
||||||
(map #(update % :transaction/post-date c/from-date))))
|
(map #(update % :transaction/post-date c/from-date))))
|
||||||
|
|
||||||
(defn sort-fn [args]
|
|
||||||
(cond
|
|
||||||
(= "client" (:sort-by args))
|
|
||||||
#(-> % :transaction/client :client/name)
|
|
||||||
|
|
||||||
:else
|
|
||||||
(keyword "transaction" (:sort-by args))))
|
|
||||||
|
|
||||||
(defn get-graphql [args]
|
(defn get-graphql [args]
|
||||||
(let [results (raw-graphql args)]
|
|
||||||
(cond->> results
|
(let [ids-to-retrieve (->> (raw-graphql-ids args)
|
||||||
(:sort-by args) (sort-by (sort-fn args))
|
(apply-sort args))
|
||||||
(= (:asc args) false) (reverse)
|
matching-count (count ids-to-retrieve)
|
||||||
true (drop (:start args 0))
|
ids-to-retrieve (apply-pagination args ids-to-retrieve )]
|
||||||
true (take (:count args 100)))))
|
|
||||||
|
[(graphql-results ids-to-retrieve args)
|
||||||
|
matching-count]
|
||||||
|
#_(time (->> (graphql-results ids-to-retrieve args)
|
||||||
|
(apply-sort args)))))
|
||||||
|
|
||||||
(defn count-graphql [args]
|
(defn count-graphql [args]
|
||||||
|
(->> (raw-graphql-ids args)
|
||||||
(->> (raw-graphql args)
|
|
||||||
(count)))
|
(count)))
|
||||||
|
|||||||
@@ -10,10 +10,8 @@
|
|||||||
(defn get-transaction-page [context args value]
|
(defn get-transaction-page [context args value]
|
||||||
(println "TRANSACTION PAGE")
|
(println "TRANSACTION PAGE")
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
transactions (map
|
[transactions transactions-count] (time (d-transactions/get-graphql (<-graphql args)))
|
||||||
->graphql
|
transactions (map ->graphql transactions)]
|
||||||
(d-transactions/get-graphql (doto (<-graphql args) println)))
|
|
||||||
transactions-count (d-transactions/count-graphql (<-graphql args))]
|
|
||||||
[{:transactions transactions
|
[{:transactions transactions
|
||||||
:total transactions-count
|
:total transactions-count
|
||||||
:count (count transactions)
|
:count (count transactions)
|
||||||
|
|||||||
Reference in New Issue
Block a user