much better sorting.

This commit is contained in:
Bryce Covert
2020-04-25 16:21:36 -07:00
parent a8736f351e
commit d799fc469d
17 changed files with 294 additions and 219 deletions

View File

@@ -1,22 +1,11 @@
(ns auto-ap.datomic.ledger
(:require [datomic.api :as d]
[auto-ap.graphql.utils :refer [->graphql limited-clients]]
[auto-ap.datomic :refer [merge-query apply-sort-2 apply-sort apply-pagination add-sorter-field]]
[auto-ap.datomic :refer [merge-query apply-sort-3 apply-pagination add-sorter-fields]]
[auto-ap.datomic :refer [uri]]
[clj-time.coerce :as c]
[clj-time.core :as time]))
(defn sort-fn [sort-by]
(cond
(= "client" sort-by)
#(-> % :journal-entry/client :client/name)
(= "vendor" sort-by)
#(-> % :journal-entry/vendor :vendor/name)
:else
(keyword "journal-entry" sort-by)))
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
@@ -24,12 +13,12 @@
:where []}
:args [db]}
(:sort-by args) (add-sorter-field {"client" ['[?e :journal-entry/client ?c]
'[?c :client/name ?sorter]]
"date" ['[?e :journal-entry/date ?sorter]]
"vendor" ['[?e :journal-entry/vendor ?sorter]]
"amount" ['[?e :journal-entry/amount ?sorter]]}
args)
(:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c]
'[?c :client/name ?sort-client]]
"date" ['[?e :journal-entry/date ?sort-date]]
"vendor" ['[?e :journal-entry/vendor ?sort-vendor]]
"amount" ['[?e :journal-entry/amount ?sort-amount]]}
args)
(limited-clients (:id args))
(merge-query {:query {:in ['[?xx ...]]
@@ -85,7 +74,7 @@
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :journal-entry/date ?base-date]]}}))]
(->> query
(d/query)
(apply-sort-2 args [:desc :asc])
(apply-sort-3 args)
(apply-pagination args))))
(defn graphql-results [ids db args]