making transactions usable.

This commit is contained in:
BC
2019-01-24 21:52:12 -08:00
parent bf6fc06244
commit 78364e6e66
2 changed files with 50 additions and 21 deletions

View File

@@ -4,6 +4,14 @@
[auto-ap.graphql.utils :refer [limited-clients]]
[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]
(let [query (-> query
(update :args conj value)
@@ -11,11 +19,23 @@
(update-in [:query :where] conj where))]
(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
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name :db/id]
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}])]
(cond-> {:query {:find [['pull '?e (into [:db/id] (condp = (:sort-by args)
"client" [{:transaction/client [:client/name]}]
nil []
[(keyword "transaction" (:sort-by args))]))
]]
:in ['$]
:where ['[?e :transaction/id]]}
:args [(d/db (d/connect uri))]}
@@ -28,27 +48,38 @@
'[?e :transaction/client ?c]
'[?c :client/original-id ?original-id])))
(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/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]
(let [results (raw-graphql args)]
(cond->> results
(:sort-by args) (sort-by (sort-fn args))
(= (:asc args) false) (reverse)
true (drop (:start args 0))
true (take (:count args 100)))))
(let [ids-to-retrieve (->> (raw-graphql-ids args)
(apply-sort args))
matching-count (count ids-to-retrieve)
ids-to-retrieve (apply-pagination args ids-to-retrieve )]
[(graphql-results ids-to-retrieve args)
matching-count]
#_(time (->> (graphql-results ids-to-retrieve args)
(apply-sort args)))))
(defn count-graphql [args]
(->> (raw-graphql args)
(->> (raw-graphql-ids args)
(count)))

View File

@@ -10,10 +10,8 @@
(defn get-transaction-page [context args value]
(println "TRANSACTION PAGE")
(let [args (assoc args :id (:id context))
transactions (map
->graphql
(d-transactions/get-graphql (doto (<-graphql args) println)))
transactions-count (d-transactions/count-graphql (<-graphql args))]
[transactions transactions-count] (time (d-transactions/get-graphql (<-graphql args)))
transactions (map ->graphql transactions)]
[{:transactions transactions
:total transactions-count
:count (count transactions)