added validation

This commit is contained in:
Bryce Covert
2019-05-12 09:27:03 -07:00
parent 2146073df8
commit 51691fa553
2 changed files with 62 additions and 47 deletions

View File

@@ -3,6 +3,7 @@
[auto-ap.datomic.transactions :as t]
[datomic.api :as d]
[auto-ap.datomic :refer [remove-nils uri merge-query]]
[auto-ap.utils :refer [dollars=]]
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
[clj-time.coerce :as c]
[clojure.set :as set])
@@ -33,6 +34,10 @@
#_(assert-admin (:id context))
(let [existing-transaction (tr/get-by-id id)
deleted (deleted-accounts existing-transaction accounts)
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
_ (when-not (dollars= 1.0 account-total)
(let [error (str "Account total (" account-total ") does not reach 100%")]
(throw (ex-info error {:validation-error error}))))
transaction [(remove-nils #:transaction-rule {:db/id (if id
id
"transaction-rule")