made it possible to change accounts.

This commit is contained in:
Bryce Covert
2020-04-29 08:21:39 -07:00
parent 3f8ce25e7f
commit 8043fb0b81
8 changed files with 246 additions and 120 deletions

View File

@@ -1,14 +1,16 @@
(ns auto-ap.graphql.accounts
(:require [datomic.api :as d]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils :refer [->graphql <-graphql] ]
[auto-ap.graphql.utils :refer [->graphql <-graphql enum->keyword] ]
[auto-ap.datomic :refer [uri merge-query remove-nils]]))
(defn get-accounts [context args value]
(->graphql (d-accounts/get-accounts (<-graphql args))))
(defn upsert-account [context args value]
(let [{{:keys [id numeric-code location account-set name type]} :account} (<-graphql args)]
(let [{{:keys [id client-overrides numeric-code location applicability account-set name type]} :account} (<-graphql args)]
(when-not id
(when (seq (d/query {:query {:find ['?e]
:in '[$ ?account-set ?numeric-code]
@@ -26,16 +28,21 @@
{:db/id (or id "new-account")
:account/name name
:account/type (keyword "account-type" (clojure.core/name type))
:account/applicability (enum->keyword applicability "account-applicability")
:account/account-set account-set
:account/location location
:account/numeric-code (if-not id
numeric-code)
:account/code (if-not id
(str numeric-code))})]
(str numeric-code))})
[:reset (or id "new-account") :account/client-overrides
(mapv
(fn [client-override]
(remove-nils
{:account-client-override/client (:client-id client-override)
:account-client-override/name (:name client-override)}))
client-overrides)]]
(and (not location) (:account/location original)) (conj [:db/retract (or id "new-account") :account/location (:account/location original)])))]
(->graphql
(if id
(:account args)
(assoc (:account args)
:id (get-in result [:tempids "new-account"])))))))
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))