Supports editing expense accounts
This commit is contained in:
@@ -8,14 +8,31 @@
|
||||
(->graphql (d-accounts/get-accounts (<-graphql args))))
|
||||
|
||||
(defn upsert-account [context args value]
|
||||
@(d/transact (d/connect uri)
|
||||
[(remove-nils
|
||||
{:db/id (:id (:account args))
|
||||
:account/name (:name (:account args))
|
||||
:account/type (keyword "account-type" (name (:type (:account args))))
|
||||
:account/account-set (:account_set (:account args))
|
||||
:account/numeric-code (if-not (:id (:account args))
|
||||
(:numeric_code (:account args)))
|
||||
})])
|
||||
(:account args))
|
||||
(let [{{:keys [id numeric-code account-set name type]} :account} (<-graphql args)]
|
||||
(when-not id
|
||||
(when (seq (d/query {:query {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
:where ['[?e :account/account-set ?account-set]
|
||||
'[?e :account/numeric-code ?numeric-code]]}
|
||||
:args [(d/db (d/connect uri)) account-set numeric-code]}))
|
||||
|
||||
(throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code)
|
||||
{} ))))
|
||||
|
||||
(let [
|
||||
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))})])]
|
||||
(->graphql
|
||||
(if id
|
||||
(:account args)
|
||||
(assoc (:account args)
|
||||
:id (get-in result [:tempids "new-account"])))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user