more code trimming for datomic.
This commit is contained in:
46
src/clj/auto_ap/datomic/users.clj
Normal file
46
src/clj/auto_ap/datomic/users.clj
Normal file
@@ -0,0 +1,46 @@
|
||||
(ns auto-ap.datomic.users
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as c]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
(update :args conj value)
|
||||
(update-in [:query :in] conj name)
|
||||
(update-in [:query :where] conj where))]
|
||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||
|
||||
(defn raw-graphql [args]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])]
|
||||
:in ['$]
|
||||
:where ['[?e :user/original-id]]}
|
||||
:args [(d/db (d/connect uri))]})]
|
||||
|
||||
(->> (d/query query)
|
||||
(map first)
|
||||
(map #(update % :user/role :db/ident))
|
||||
)))
|
||||
|
||||
(defn sort-fn [args]
|
||||
(cond
|
||||
(= "client" (:sort-by args))
|
||||
#(-> % :payment/client :client/name)
|
||||
|
||||
:else
|
||||
(keyword "payment" (: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 20)))))
|
||||
|
||||
(defn count-graphql [args]
|
||||
|
||||
(->> (raw-graphql args)
|
||||
(count)))
|
||||
Reference in New Issue
Block a user