more code trimming for datomic.
This commit is contained in:
@@ -678,8 +678,9 @@
|
||||
(defn load-users [users]
|
||||
(->> users
|
||||
(map
|
||||
(fn [{:keys [id role provider-id provider companies]}]
|
||||
(fn [{:keys [id role provider-id provider companies name]}]
|
||||
(remove-nils #:user {:original-id id
|
||||
:name name
|
||||
:role (keyword "user-role" role)
|
||||
:provider-id provider-id
|
||||
:provider provider
|
||||
|
||||
46
src/clj/auto_ap/datomic/users.clj
Normal file
46
src/clj/auto_ap/datomic/users.clj
Normal file
@@ -0,0 +1,46 @@
|
||||
(ns auto-ap.datomic.users
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as c]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
(update :args conj value)
|
||||
(update-in [:query :in] conj name)
|
||||
(update-in [:query :where] conj where))]
|
||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||
|
||||
(defn raw-graphql [args]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])]
|
||||
:in ['$]
|
||||
:where ['[?e :user/original-id]]}
|
||||
:args [(d/db (d/connect uri))]})]
|
||||
|
||||
(->> (d/query query)
|
||||
(map first)
|
||||
(map #(update % :user/role :db/ident))
|
||||
)))
|
||||
|
||||
(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)))
|
||||
@@ -13,6 +13,7 @@
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.db.users :as users]
|
||||
@@ -89,8 +90,7 @@
|
||||
:body {:type 'String}
|
||||
:scheduled {:type 'String}
|
||||
:sent {:type 'String}
|
||||
:vendor {:type :vendor
|
||||
:resolve :get-vendor-for-invoice}
|
||||
:vendor {:type :vendor}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,8 +145,7 @@
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:companies {:type '(list :company)
|
||||
:resolve :get-user-companies}}}
|
||||
:clients {:type '(list :company)}}}
|
||||
|
||||
:expense_account {:fields {:id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
@@ -407,29 +406,14 @@
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count reminders))}] extra-context)))
|
||||
|
||||
(defn get-vendor-for-invoice [context args value]
|
||||
(->graphql
|
||||
(if-let [vendor-cache (:vendor-cache context)]
|
||||
(vendor-cache (:vendor_id value))
|
||||
(vendors/get-by-id (:vendor_id value)))))
|
||||
|
||||
(defn get-check-by-id [context args value]
|
||||
(->graphql
|
||||
(checks/get-by-id (:check_id value))))
|
||||
|
||||
(defn get-invoices-checks [context args value]
|
||||
(->graphql
|
||||
(invoices-checks/get-for-invoice-id (:id value))))
|
||||
|
||||
(defn get-checks-invoices [context args value]
|
||||
(->graphql
|
||||
(invoices-checks/get-for-check-id (:id value))))
|
||||
|
||||
(defn get-company-for-invoice [context args value]
|
||||
(->graphql
|
||||
(if-let [company-cache (:company-cache context)]
|
||||
(company-cache (:company_id value))
|
||||
(companies/get-by-id (:company_id value)))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn bank-account-for-check [context args value]
|
||||
(->graphql
|
||||
@@ -461,13 +445,8 @@
|
||||
(defn get-user [context args value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [
|
||||
users (users/get-all)
|
||||
|
||||
extra-context (cond-> context
|
||||
(executor/selects-field? context :user/companies) (assoc :company-cache (by :id (companies/get-all))))]
|
||||
(resolve/with-context
|
||||
(->graphql users) extra-context)))
|
||||
(let [users (d-users/get-graphql args)]
|
||||
(->graphql users)))
|
||||
|
||||
(defn get-vendor [context args value]
|
||||
(->graphql
|
||||
@@ -495,13 +474,6 @@
|
||||
:get-payment-page gq-checks/get-payment-page
|
||||
:get-transaction-page gq-transactions/get-transaction-page
|
||||
:get-reminder-page get-reminder-page
|
||||
:get-vendor-for-invoice get-vendor-for-invoice
|
||||
:get-check-for-transaction gq-transactions/get-check-for-transaction
|
||||
:get-company-for-invoice get-company-for-invoice
|
||||
:get-invoices-checks get-invoices-checks
|
||||
:get-checks-invoices get-checks-invoices
|
||||
:get-check-by-id get-check-by-id
|
||||
:get-invoices-expense-accounts gq-invoices/get-invoices-expense-accounts
|
||||
:get-company get-company
|
||||
:get-user get-user
|
||||
:get-user-companies get-user-companies
|
||||
|
||||
Reference in New Issue
Block a user