More standardization

This commit is contained in:
Bryce Covert
2020-08-05 00:29:21 -07:00
parent e1ffeda851
commit 0fd8d4a1c1
8 changed files with 299 additions and 285 deletions

View File

@@ -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)))

View File

@@ -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)