lots of fixes.

This commit is contained in:
Bryce Covert
2020-04-21 07:13:42 -07:00
parent 01c776a72e
commit 9cb42be9e8
5 changed files with 108 additions and 72 deletions

View File

@@ -33,7 +33,7 @@
:db/fn (d/function '{:lang "clojure"
:params [db e a amount]
:code [[:db/add e a
(-> (d/entity db e) a (+ amount))]] })}]] )
(-> (d/entity db e) a (+ amount))]] })}]] )
(defn fix-pay-function [conn]
[[{:db/ident :pay
@@ -53,6 +53,24 @@
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]])
(defn reset-function [conn]
[[{:db/ident :reset
:db/doc "Resets a relationship to the values specified "
:db/fn (d/function '{:lang "clojure"
:params [db e a vs]
:code (let [ids (when-not (string? e)
(->> (d/query {:query {:find ['?z]
:in ['$ '?e '?a]
:where [['?e '?a '?z]]}
:args [db e a]})
(map first)))
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))
(seq vs) (conj {:db/id e
a vs})))})}]])
(defn -main [& args]
(println "Creating database ..." uri)
(doto (d/create-database uri) println)
@@ -174,7 +192,7 @@
:db/doc "Overrides per-client"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
}]
:auto-ap/add-reset-rels {:txes-fn `reset-function}}]
(println "Conforming database...")
(c/ensure-conforms conn norms-map)
(when (not (seq args))

View File

@@ -39,11 +39,25 @@
(defn terms-for-client-id [vendor client-id]
(->>
(filter
(fn [to]
(= (:db/id (:vendor-terms-override/client to))
client-id))
(:vendor/terms-overrides vendor))
first
:vendor-terms-override/terms))
(or
(->>
(filter
(fn [to]
(= (:db/id (:vendor-terms-override/client to))
client-id))
(:vendor/terms-overrides vendor))
first
:vendor-terms-override/terms)
(:vendor/terms vendor)))
(defn account-for-client-id [vendor client-id]
(or
(->>
(filter
(fn [to]
(= (:db/id (:vendor-account-override/client to))
client-id))
(:vendor/account-overrides vendor))
first
:vendor-account-override/account)
(:vendor/default-account vendor)))