Getting closer to datomic cloud
This commit is contained in:
@@ -5,18 +5,17 @@
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.square.core :as square]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql assert-admin can-see-client? is-admin?]]
|
||||
:refer [->graphql assert-admin can-see-client? is-admin? attach-tracing-resolvers]]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.client.api :as dc]
|
||||
[unilog.context :as lc]
|
||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]
|
||||
[com.brunobonacci.mulog :as mu])
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.client.api :as dc])
|
||||
(:import
|
||||
(java.util UUID)
|
||||
(org.apache.commons.codec.binary Base64)))
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
[auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query pull-many-by-id]]
|
||||
[auto-ap.graphql.utils
|
||||
:refer
|
||||
[<-graphql assert-admin ident->enum-f result->page]]
|
||||
[<-graphql assert-admin ident->enum-f result->page attach-tracing-resolvers]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]
|
||||
[datomic.client.api :as dc]
|
||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]))
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:import-batch/external-id
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn random-tempid remove-nils upsert-entity]]
|
||||
[auto-ap.datomic
|
||||
:refer [conn pull-attr pull-many pull-ref random-tempid upsert-entity]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
@@ -22,10 +23,7 @@
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[manifold.deferred :as de]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(defn ->graphql [invoice user ]
|
||||
@@ -139,7 +137,7 @@
|
||||
|
||||
(when (and (= :allowance/denied
|
||||
(:account/invoice-allowance account))
|
||||
(not= (:db/id (:vendor/default-account (d/entity (d/db conn) vendor_id)))
|
||||
(not= (pull-ref (dc/db conn) vendor_id :vendor/default-account)
|
||||
(:db/id account)))
|
||||
(let [err (str "Account isn't allowed for invoice use.")]
|
||||
(throw (ex-info err
|
||||
@@ -262,30 +260,32 @@
|
||||
|
||||
(defn all-ids-not-locked [all-ids]
|
||||
(->> all-ids
|
||||
(d/q '[:find [?i ...]
|
||||
(dc/q '[:find ?i
|
||||
:in $ [?i ...]
|
||||
:where
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn))))
|
||||
(dc/db conn))
|
||||
(map first)))
|
||||
|
||||
(defn void-invoices [context args _]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||
voidable-cash-payments (d/q '[:find [?p ...]
|
||||
:in $ [?i ...]
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/payment ?p]
|
||||
[?p :payment/type :payment-type/cash]
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn)
|
||||
all-ids)
|
||||
voidable-cash-payments (->> (dc/q '[:find ?p
|
||||
:in $ [?i ...]
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/payment ?p]
|
||||
[?p :payment/type :payment-type/cash]
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(dc/db conn)
|
||||
all-ids)
|
||||
(map first))
|
||||
]
|
||||
(log/info "Voiding " (count voidable-cash-payments) "cash payments first")
|
||||
(gq-checks/void-payments-internal voidable-cash-payments (:id context))
|
||||
@@ -422,11 +422,11 @@
|
||||
(throw (ex-info "Client is required"
|
||||
{:validation-error "client is required"})))
|
||||
(let [args (assoc args :id (:id context))
|
||||
locations (:client/locations (d/pull (d/db conn)
|
||||
[:client/locations]
|
||||
(:client_id args)))
|
||||
locations (pull-attr (dc/db conn)
|
||||
:client/locations
|
||||
(:client_id args))
|
||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||
invoices (d/pull-many (d/db conn) '[:db/id :invoice/total] (vec all-ids))
|
||||
invoices (pull-many (dc/db conn) '[:db/id :invoice/total] (vec all-ids))
|
||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) (:accounts args)))]
|
||||
(log/info "client is" locations)
|
||||
(when
|
||||
@@ -434,7 +434,7 @@
|
||||
(let [error (str "Account total (" account-total ") does not reach 100%")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
(doseq [a (:accounts args)
|
||||
:let [{:keys [:account/location :account/name]} (d/entity (d/db conn) (:account_id a))]]
|
||||
:let [{:keys [:account/location :account/name]} (dc/pull (dc/db conn) [:account/location :account/name] (:account_id a))]]
|
||||
(when (and location (not= location (:location a)))
|
||||
(let [err (str "Account " name " uses location " (:location a) ", but is supposed to be " location)]
|
||||
(throw (ex-info err {:validation-error err}) )))
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.client.api :as dc]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(defn plaid-link-token [context value _]
|
||||
(when-not (:client_id value)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
:refer [->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
attach-tracing-resolvers
|
||||
assert-can-see-client
|
||||
assert-not-locked
|
||||
assert-power-user
|
||||
@@ -34,10 +35,7 @@
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]))
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user