Can edit locations now.

This commit is contained in:
Bryce Covert
2019-04-14 08:32:24 -07:00
parent 4018d9aa8d
commit c44a36c815
8 changed files with 50 additions and 20 deletions

View File

@@ -8,7 +8,7 @@
(->graphql (d-accounts/get-accounts (<-graphql args))))
(defn upsert-account [context args value]
(let [{{:keys [id numeric-code account-set name type]} :account} (<-graphql args)]
(let [{{:keys [id numeric-code location account-set name type]} :account} (<-graphql args)]
(when-not id
(when (seq (d/query {:query {:find ['?e]
:in '[$ ?account-set ?numeric-code]
@@ -19,17 +19,20 @@
(throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code)
{} ))))
(let [
(let [original (if id (d/entity (d/db (d/connect uri)) id))
result @(d/transact (d/connect uri)
[(remove-nils
{:db/id (or id "new-account")
:account/name name
:account/type (keyword "account-type" (clojure.core/name type))
:account/account-set account-set
:account/numeric-code (if-not id
numeric-code)
:account/code (if-not id
(str numeric-code))})])]
(cond->
[(remove-nils
{:db/id (or id "new-account")
:account/name name
:account/type (keyword "account-type" (clojure.core/name type))
:account/account-set account-set
:account/location location
:account/numeric-code (if-not id
numeric-code)
:account/code (if-not id
(str numeric-code))})]
(and (not location) (:account/location original)) (conj [:db/retract (or id "new-account") :account/location (:account/location original)])))]
(->graphql
(if id
(:account args)