Adds reports page.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
|
||||
[auto-ap.datomic.migrate.audit :as audit]
|
||||
[auto-ap.datomic.migrate.clients :as clients]
|
||||
[auto-ap.datomic.migrate.reports :as reports]
|
||||
[auto-ap.datomic.migrate.invoice-converter
|
||||
:refer [add-import-status-existing-invoices]]
|
||||
[auto-ap.datomic.migrate.ledger :as ledger]
|
||||
@@ -497,6 +498,7 @@
|
||||
clients/norms-map
|
||||
ledger/norms-map
|
||||
yodlee2/norms-map
|
||||
reports/norms-map
|
||||
plaid/norms-map
|
||||
audit/norms-map
|
||||
vendors/norms-map)]
|
||||
|
||||
27
src/clj/auto_ap/datomic/migrate/reports.clj
Normal file
27
src/clj/auto_ap/datomic/migrate/reports.clj
Normal file
@@ -0,0 +1,27 @@
|
||||
(ns auto-ap.datomic.migrate.reports)
|
||||
|
||||
(def norms-map {::add-reports
|
||||
{:txes [[{:db/ident :report/client
|
||||
:db/doc "Which client(s) this is for"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many}
|
||||
|
||||
{:db/ident :report/name
|
||||
:db/doc "A description for the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/key
|
||||
:db/doc "The s3 key for the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/created
|
||||
:db/doc "When this report was created"
|
||||
:db/valueType :db.type/instant
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/url
|
||||
:db/doc "Where to download the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]]}})
|
||||
64
src/clj/auto_ap/datomic/reports.clj
Normal file
64
src/clj/auto_ap/datomic/reports.clj
Normal file
@@ -0,0 +1,64 @@
|
||||
(ns auto-ap.datomic.reports
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query]]
|
||||
[auto-ap.graphql.utils :refer [can-see-client? limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :report/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :report/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :report/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"created" ['[?e :report/created ?sort-created]]
|
||||
"name" ['[?e :report/name ?sort-name]
|
||||
]}
|
||||
args)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :report/created ?sort-default]]}}))]
|
||||
(->> query
|
||||
(d/query)
|
||||
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
||||
(apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(let [results (->> (d/pull-many db '[:db/id :report/client :report/created :report/url :report/name]
|
||||
ids)
|
||||
(map #(update % :report/created c/from-date))
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
(map results)
|
||||
(filter identity)
|
||||
|
||||
(map first)
|
||||
(filter (fn [r]
|
||||
(every?
|
||||
#(can-see-client? (:id args) %)
|
||||
(map :db/id (:report/client r))))))))
|
||||
|
||||
(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]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user