Supports vendors not loading

This commit is contained in:
2022-04-11 17:26:03 -07:00
parent e4da1376f8
commit 2e4e693bc6
19 changed files with 412 additions and 657 deletions

View File

@@ -1,8 +1,10 @@
(ns auto-ap.datomic.vendors
(:require [datomic.api :as d]
[auto-ap.graphql.utils :refer [limited-clients ]]
(:require
[auto-ap.datomic :refer [conn merge-query uri add-sorter-fields apply-pagination merge-query apply-sort-3]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clojure.string :as str]
[datomic.api :as d]))
[auto-ap.datomic :refer [uri conn merge-query]]))
(defn <-datomic [a]
(cond-> a
(:vendor/legal-entity-tin-type a) (update :vendor/legal-entity-tin-type :db/ident)
@@ -58,6 +60,30 @@
(update usages v (fnil conj []) {:client-id c :count cnt}))
{})))
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
:in ['$]
:where []}
:args [db]}
(:sort args) (add-sorter-fields {"name" ['[?e :vendor/name ?sort-name]]}
args)
(not (str/blank? (:name-like args)))
(merge-query {:query {:in ['?name-like]
:where ['[?e :vendor/name ?n]
'[(re-find ?name-like ?n)]]}
:args [(re-pattern (str "(?i)" (:name-like args)))]})
true
(merge-query {:query {:find ['?e]
:where ['[?e :vendor/name]]}}))]
(cond->> query
true (d/query)
true (apply-sort-3 args)
true (apply-pagination args))))
(defn trim-usage [v limited-clients]
(->> (if limited-clients
(update v :usage (fn [usages]
@@ -73,17 +99,23 @@
))
(defn graphql-results [ids db args]
(let [results (->> (d/pull-many db default-read ids)
(group-by :db/id))
vendors (->> ids
(map results)
(map first)
(map #(cleanse (:id args) %))
(map <-datomic))]
vendors))
(defn get-graphql [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 <-datomic)
(map #(trim-usage % (limited-clients (:id args))))
#_(map #(assoc % :usage (get usages (:db/id %))))))
(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-graphql-by-id [args id]
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]