missing files.
This commit is contained in:
63
src/clj/auto_ap/graphql/import_batch.clj
Normal file
63
src/clj/auto_ap/graphql/import_batch.clj
Normal file
@@ -0,0 +1,63 @@
|
||||
(ns auto-ap.graphql.import-batch
|
||||
(:require
|
||||
[clojure.tools.logging :as log]
|
||||
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 merge-query conn]]
|
||||
[auto-ap.graphql.utils :refer [<-graphql assert-admin ident->enum-f result->page]]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:import-batch/external-id
|
||||
:import-batch/date
|
||||
:import-batch/imported
|
||||
:import-batch/suppressed
|
||||
:import-batch/extant
|
||||
:import-batch/user-name
|
||||
{:import-batch/source [:db/ident]}
|
||||
{:import-batch/status [:db/ident]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
(:sort args) (add-sorter-fields {"date" ['[?e :import-batch/date ?sort-date]]}
|
||||
args)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?e]
|
||||
:where ['[?e :import-batch/date]]}}))]
|
||||
|
||||
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
(map results)
|
||||
(map first))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [db (d/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
[(graphql-results ids-to-retrieve db args)
|
||||
matching-count]))
|
||||
|
||||
(defn get-import-batch-page [context args value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc (:filters args) :id (:id context))
|
||||
[values matching-count] (get-graphql (<-graphql args))]
|
||||
(result->page (->> values
|
||||
(map (ident->enum-f :import-batch/source))
|
||||
(map (ident->enum-f :import-batch/status))
|
||||
(map #(update % :import-batch/date clj-time.coerce/to-date-time)))
|
||||
matching-count :data args)))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user