Supports vendors not loading
This commit is contained in:
@@ -134,13 +134,18 @@
|
||||
|
||||
(defn bulk-code-transactions [context args _]
|
||||
(assert-admin (:id context))
|
||||
(when-not (:client_id args)
|
||||
(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 (:filters args))))
|
||||
(:client_id args)))
|
||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||
transactions (d/pull-many (d/db conn) '[:db/id :transaction/amount] (vec all-ids))
|
||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) (:accounts args)))]
|
||||
(log/info "client is" locations)
|
||||
|
||||
(when
|
||||
(and
|
||||
(seq (:accounts args))
|
||||
@@ -149,14 +154,13 @@
|
||||
(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))
|
||||
client (d/entity (d/db conn) (:client_id (:filters args)))]]
|
||||
:let [{:keys [:account/location :account/name]} (d/entity (d/db conn) (: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}) )))
|
||||
|
||||
(when (and (not location)
|
||||
(not (get (into #{"Shared"} (:client/locations client))
|
||||
(not (get (into #{"Shared"} locations)
|
||||
(:location a))))
|
||||
(let [err (str "Account " name " uses location " (:location a) ", but doesn't belong to the client.")]
|
||||
(throw (ex-info err {:validation-error err}) ))))
|
||||
@@ -599,6 +603,7 @@
|
||||
:resolve :mutation/bulk-change-transaction-status}
|
||||
:bulk_code_transactions {:type :message
|
||||
:args {:filters {:type :transaction_filters}
|
||||
:client_id {:type :id}
|
||||
:vendor {:type :id}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:accounts {:type '(list :edit_percentage_account)}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
(ns auto-ap.graphql.vendors
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client assert-admin is-admin? enum->keyword]]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils audit-transact conn]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(:require
|
||||
[auto-ap.datomic :refer [audit-transact conn remove-nils]]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql <-graphql assert-admin enum->keyword is-admin? result->page]]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule schedule_payment_dom terms_overrides account_overrides] :as in} :vendor} value]
|
||||
(when id
|
||||
@@ -114,10 +112,16 @@
|
||||
(audit-transact transaction (:id context))
|
||||
to))
|
||||
|
||||
(defn get-graphql [context args value]
|
||||
#_(defn get-graphql [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql (assoc args :id (:id context)))))
|
||||
|
||||
(defn get-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [args (assoc args :id (:id context))
|
||||
[vendors vendors-count ] (d-vendors/get-graphql (<-graphql args))]
|
||||
(result->page vendors vendors-count :vendors args)))
|
||||
|
||||
(defn get-by-id [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql-by-id (assoc args :id (:id context))
|
||||
|
||||
Reference in New Issue
Block a user