tons of small fixes.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.datomic.vendors
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.datomic :refer [uri]]))
|
||||
[auto-ap.graphql.utils :refer [limited-clients ]]
|
||||
|
||||
[auto-ap.datomic :refer [uri conn merge-query]]))
|
||||
(defn cleanse [id vendor]
|
||||
(let [clients (if-let [clients (limited-clients id)]
|
||||
(set (map :db/id clients))
|
||||
@@ -18,14 +19,42 @@
|
||||
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :client/code :db/id]}]
|
||||
:vendor/automatically-paid-when-due [:db/id :client/name]}])
|
||||
|
||||
(defn get-graphql [args]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
(defn get-usages [args]
|
||||
(->> (cond-> {:query {:find ['?v '?c '(count ?e)]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
:where ['[?v :vendor/name]
|
||||
'(or-join [?v ?c ?e]
|
||||
(and
|
||||
[?e :invoice/vendor ?v]
|
||||
[?e :invoice/client ?c])
|
||||
(and
|
||||
[?e :transaction/vendor ?v]
|
||||
[?e :transaction/client ?c])
|
||||
(and
|
||||
[?e :journal-entry/vendor ?v]
|
||||
[?e :journal-entry/client ?c]))]}
|
||||
:args [(d/db conn)]}
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['?xx]
|
||||
:where [['(get ?xx ?c)]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))))
|
||||
(reduce
|
||||
(fn [usages [v c cnt]]
|
||||
(update usages v (fnil conj []) {:client-id c :count cnt}))
|
||||
{})))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [usages (time (get-usages args))]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))
|
||||
(map #(assoc % :usage (get usages (:db/id %)))))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user