More standardization
This commit is contained in:
@@ -1,36 +1,40 @@
|
||||
(ns auto-ap.datomic.clients
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]))
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(defn cleanse [e]
|
||||
(-> e
|
||||
(update :client/location-matches
|
||||
(fn [lms]
|
||||
(map #(assoc % :location-match/match (first (:location-match/matches %))) lms)))
|
||||
(update :client/bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [i ba]
|
||||
(-> ba
|
||||
(update :bank-account/type :db/ident )
|
||||
(update :bank-account/sort-order (fn [so] (or so i)))))
|
||||
(range) bas)))))
|
||||
(defn get-all []
|
||||
|
||||
(->> (d/q '[:find (pull ?e [* {:client/address [*]}])
|
||||
(->> (d/q '[:find (pull ?e [*
|
||||
{:client/address [*]}
|
||||
{:client/bank-accounts [* {:bank-account/type [*]}]}])
|
||||
:where [?e :client/name]]
|
||||
(d/db (d/connect uri)))
|
||||
(map first)
|
||||
(map (fn [c]
|
||||
(update c :client/location-matches
|
||||
(fn [lms]
|
||||
|
||||
(map #(assoc % :location-match/match (first (:location-match/matches %))) lms)))))
|
||||
(map (fn [c]
|
||||
(update c :client/bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [i ba]
|
||||
(-> ba
|
||||
(update :bank-account/type :db/ident )
|
||||
(update :bank-account/sort-order (fn [so] (or so i)))))
|
||||
(range) bas)))))
|
||||
(map cleanse)
|
||||
|
||||
))
|
||||
(defn get-by-id [id]
|
||||
(->>
|
||||
(d/query (-> {:query {:find ['(pull ?e [*])]
|
||||
(d/query (-> {:query {:find ['(pull ?e [* {:client/bank-accounts [* {:bank-account/type [*]}]}])]
|
||||
:in ['$ '?e]
|
||||
:where [['?e]]}
|
||||
:args [(d/db (d/connect uri)) id]}
|
||||
))
|
||||
(first)
|
||||
(first)
|
||||
(cleanse)
|
||||
#_(map first)
|
||||
|
||||
#_(first)))
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
new-id-set (set (map :db/id vs))
|
||||
retract-ids (filter (complement new-id-set) ids)]
|
||||
(cond-> []
|
||||
true (into (map (fn [i] [:db/retractEntity i ]) retract-ids))
|
||||
true (into (map (fn [i] [:db/retract e a i ]) retract-ids))
|
||||
(seq vs) (conj {:db/id e
|
||||
a vs})))})}]])
|
||||
|
||||
@@ -308,7 +308,8 @@
|
||||
{:db/ident :invoice/automatically-paid-when-due
|
||||
:db/doc "Whether this invoice should be marked as paid when it's due"
|
||||
:db/valueType :db.type/boolean
|
||||
:db/cardinality :db.cardinality/one}]]}}
|
||||
:db/cardinality :db.cardinality/one}]]}
|
||||
:auto-ap/fix-reset-rels {:txes-fn `reset-function}}
|
||||
]
|
||||
(println "Conforming database...")
|
||||
(c/ensure-conforms conn norms-map)
|
||||
|
||||
@@ -65,7 +65,8 @@
|
||||
{
|
||||
:location_match
|
||||
{:fields {:location {:type 'String}
|
||||
:match {:type 'String}}}
|
||||
:match {:type 'String}
|
||||
:id {:type :id}}}
|
||||
|
||||
:client
|
||||
{:fields {:id {:type :id}
|
||||
@@ -526,7 +527,8 @@
|
||||
:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
||||
:amount {:type 'Float}}}
|
||||
:edit_location_match {:fields {:location {:type 'String}
|
||||
:match {:type 'String}}}
|
||||
:match {:type 'String}
|
||||
:id {:type :id}}}
|
||||
|
||||
:edit_forecasted_transaction {:fields {:identifier {:type 'String}
|
||||
:id {:type :id}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client?]]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(defn assert-client-code-is-unique [code]
|
||||
(when (seq (d/query {:query {:find '[?id]
|
||||
@@ -76,6 +77,7 @@
|
||||
:forecasted-transaction/amount (:amount %)}
|
||||
)
|
||||
(:forecasted_transactions edit_client))]]
|
||||
_ (log/info "upserting client" transactions)
|
||||
result @(d/transact (d/connect uri) transactions)]
|
||||
(-> result :tempids (get id) (or id) d-clients/get-by-id
|
||||
(update :client/location-matches
|
||||
|
||||
Reference in New Issue
Block a user