50 lines
1.6 KiB
Clojure
50 lines
1.6 KiB
Clojure
(ns auto-ap.datomic.checks
|
|
(:require [datomic.api :as d]
|
|
[auto-ap.datomic :refer [uri]]
|
|
[clj-time.coerce :as c]))
|
|
|
|
(defn add-arg [query name value where]
|
|
(-> query
|
|
(update :args conj value)
|
|
(update-in [:query :in] conj name)
|
|
(update-in [:query :where] conj where)))
|
|
|
|
(defn raw-graphql [args]
|
|
(->> (d/query
|
|
(cond-> {:query {:find ['(pull ?e [*
|
|
{:payment/client [:client/name :db/id]}
|
|
{:payment/vendor [:vendor/name :db/id]}
|
|
{:payment/status [:db/ident]}])]
|
|
:in ['$]
|
|
:where ['[?e :payment/original-id]]}
|
|
:args [(d/db (d/connect uri))]}
|
|
|
|
(:company-id args) (add-arg '?company-id (Long/parseLong (:company-id args))
|
|
'[?e :payment/client ?company-id])))
|
|
(map first)
|
|
|
|
(map #(update % :payment/date c/from-date))
|
|
(map #(update % :payment/status :db/ident))
|
|
#_(map #(update % :transaction/post-date c/from-date))))
|
|
|
|
(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)))
|