supports starting from scratch.
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
:auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]] :requires [:auto-ap/add-bank-account-codes]}
|
||||
:auto-ap/rename-codes-1 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-codes-1 :requires [:auto-ap/add-nick-the-greek]}
|
||||
:auto-ap/invoice-converter {:txes auto-ap.datomic.migrate.invoice-converter/add-matches :requires [:auto-ap/rename-codes-1]}
|
||||
:auto-ap/starter {:txes auto-ap.datomic.migrate.invoice-converter/add-starter :requires [:auto-ap/invoice-converter]}
|
||||
:auto-ap/starter {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-starter :requires [:auto-ap/invoice-converter]}
|
||||
:auto-ap/add-default-location {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location :requires [:auto-ap/invoice-converter]}
|
||||
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2 :requires [:auto-ap/add-default-location]}
|
||||
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status :requires [:auto-ap/add-default-location-2]}
|
||||
|
||||
@@ -23,11 +23,16 @@
|
||||
:db/doc "The location of the location match"}
|
||||
]])
|
||||
|
||||
(def add-starter
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/matches ["campbell brewing company"]
|
||||
:client/location-matches [{:location-match/location "CB"
|
||||
:location-match/matches ["campbell brewing company"]}]}]])
|
||||
(defn add-starter [conn]
|
||||
(if (seq (d/query {:query {:find '[?e]
|
||||
:in ['$]
|
||||
:where ['[?e :client/code "CBC"]]}
|
||||
:args [(d/db conn)]}))
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/matches ["campbell brewing company"]
|
||||
:client/location-matches [{:location-match/location "CB"
|
||||
:location-match/matches ["campbell brewing company"]}]}]]
|
||||
[[]]))
|
||||
|
||||
(defn add-default-location [conn]
|
||||
[[{:db/ident :client/default-location
|
||||
@@ -36,8 +41,13 @@
|
||||
:db/doc "The default location if one can't be found"}]])
|
||||
|
||||
(defn add-default-location-2 [conn]
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/default-location "CB"}]])
|
||||
(if (seq (d/query {:query {:find '[?e]
|
||||
:in ['$]
|
||||
:where ['[?e :client/code "CBC"]]}
|
||||
:args [(d/db conn)]}))
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/default-location "CB"}]]
|
||||
[[]]))
|
||||
|
||||
(def add-import-status
|
||||
[[{:db/ident :invoice/import-status
|
||||
|
||||
@@ -27,7 +27,11 @@
|
||||
first)))
|
||||
|
||||
(defn find-or-insert! [{:keys [:user/provider :user/provider-id] :as new-user}]
|
||||
(let [user (some-> {:query [:find '(pull ?e [*
|
||||
(let [is-first-user? (not (seq (d/query {:query [:find '?e
|
||||
:in '$
|
||||
:where '[?e :user/provider]]
|
||||
:args [(d/db (d/connect uri))]})))
|
||||
user (some-> {:query [:find '(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])
|
||||
:in '$ '?provider '?provider-id
|
||||
@@ -40,7 +44,9 @@
|
||||
(update :user/role :db/ident))]
|
||||
(if user
|
||||
user
|
||||
(let [new-user-trans @(d/transact (d/connect uri) [(assoc new-user :db/id "user")])]
|
||||
(let [new-user-trans @(d/transact (d/connect uri) [(cond-> new-user
|
||||
true (assoc :db/id "user")
|
||||
is-first-user? (assoc :user/role :user-role/admin))])]
|
||||
(println new-user-trans)
|
||||
(get-by-id (-> new-user-trans :tempids (get "user")))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user