a bunch of cleanup to remove stuff
This commit is contained in:
@@ -4,23 +4,6 @@
|
||||
[datomic.api :as dc]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
(update :args conj value)
|
||||
(update-in [:query :in] conj name)
|
||||
(update-in [:query :where] conj where))]
|
||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->> [(dc/pull (dc/db conn)
|
||||
'[*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}]
|
||||
id)]
|
||||
(map #(update % :user/role :db/ident))
|
||||
first))
|
||||
|
||||
|
||||
(defn find-or-insert! [{:keys [:user/provider :user/provider-id ] :as new-user}]
|
||||
(let [is-first-user? (not (seq (dc/q [:find '?e
|
||||
:in '$
|
||||
@@ -43,30 +26,3 @@
|
||||
user-id)
|
||||
:user/role :db/ident)))
|
||||
|
||||
(defn raw-graphql [_]
|
||||
(->> (dc/q {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])]
|
||||
:in ['$]
|
||||
:where ['[?e :user/role]]}
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(map #(update % :user/role :db/ident))
|
||||
))
|
||||
|
||||
(defn sort-fn [args]
|
||||
(cond
|
||||
(= "client" (:sort-by args))
|
||||
#(-> % :payment/client :client/name)
|
||||
|
||||
:else
|
||||
(keyword "payment" (:sort-by args))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [results (raw-graphql args)]
|
||||
(cond->> results
|
||||
(:sort-by args) (sort-by (sort-fn args))
|
||||
(= (:asc args) false) (reverse)
|
||||
true (drop (:start args 0))
|
||||
true (take (:count args 500)))))
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(ns auto-ap.graphql
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn merge-query query2]]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.graphql.accounts :as gq-accounts]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.clients :as gq-clients]
|
||||
@@ -16,7 +15,6 @@
|
||||
[auto-ap.graphql.sales-orders :as gq-sales-orders]
|
||||
[auto-ap.graphql.transaction-rules :as gq-transaction-rules]
|
||||
[auto-ap.graphql.transactions :as gq-transactions]
|
||||
[auto-ap.graphql.users :as gq-users]
|
||||
[auto-ap.graphql.utils :refer [assert-admin attach-tracing-resolvers]]
|
||||
[auto-ap.graphql.vendors :as gq-vendors]
|
||||
[auto-ap.graphql.yodlee-merchants :as ym]
|
||||
@@ -353,14 +351,6 @@
|
||||
:resolve :get-cash-flow}
|
||||
|
||||
|
||||
:account_page {:type :account_page
|
||||
:args {:name_like {:type 'String}
|
||||
:numeric_code {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:per_page {:type 'Int}
|
||||
:sort {:type '(list :sort_item)}}
|
||||
:resolve :get-accounts}
|
||||
|
||||
:all_accounts {:type '(list :account)
|
||||
:args {}
|
||||
:resolve :get-all-accounts}
|
||||
@@ -407,8 +397,7 @@
|
||||
:per_page {:type 'Int}
|
||||
:sort {:type '(list :sort_item)}}
|
||||
:resolve :get-vendor}
|
||||
:user {:type '(list :user)
|
||||
:resolve :get-user}
|
||||
|
||||
:vendor_by_id {:type :vendor
|
||||
:args {:id {:type :id}}
|
||||
:resolve :vendor-by-id}
|
||||
@@ -427,12 +416,6 @@
|
||||
:date_range {:fields {:start {:type :iso_date}
|
||||
:end {:type :iso_date}}}
|
||||
|
||||
:edit_user
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:role {:type :role}
|
||||
:clients {:type '(list String)}}}
|
||||
|
||||
:add_contact
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
@@ -574,11 +557,6 @@
|
||||
:to {:type :id}}
|
||||
:resolve :mutation/merge-vendors}
|
||||
|
||||
:edit_user
|
||||
{:type :user
|
||||
:args {:edit_user {:type :edit_user}}
|
||||
:resolve :mutation/edit-user}
|
||||
|
||||
:upsert_vendor
|
||||
{:type :vendor
|
||||
:args {:vendor {:type :add_vendor}}
|
||||
@@ -588,11 +566,7 @@
|
||||
{:type :transaction_rule
|
||||
:args {:transaction_rule {:type :edit_transaction_rule}}
|
||||
:resolve :mutation/upsert-transaction-rule}
|
||||
|
||||
:upsert_account
|
||||
{:type :account
|
||||
:args {:account {:type :edit_account}}
|
||||
:resolve :mutation/upsert-account}}})
|
||||
}})
|
||||
|
||||
|
||||
(defn snake->kebab [s]
|
||||
@@ -619,18 +593,6 @@
|
||||
node))
|
||||
m))
|
||||
|
||||
(defn get-user [context args _]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [users (->> (d-users/get-graphql args)
|
||||
(map (fn [u]
|
||||
(assoc u :impersonate_jwt
|
||||
(jwt/sign (auth/user->jwt u "FAKE_TOKEN")
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512})))))]
|
||||
(->graphql users)))
|
||||
|
||||
|
||||
|
||||
(defn get-expense-account-stats [_ {:keys [client_id] } _]
|
||||
(let [query (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
@@ -791,7 +753,6 @@
|
||||
(-> integreat-schema
|
||||
(attach-tracing-resolvers
|
||||
{
|
||||
:get-accounts gq-accounts/get-graphql
|
||||
:get-all-accounts gq-accounts/get-all-graphql
|
||||
:get-transaction-rule-page gq-transaction-rules/get-transaction-rule-page
|
||||
:get-transaction-rule-matches gq-transaction-rules/get-transaction-rule-matches
|
||||
@@ -802,14 +763,11 @@
|
||||
:get-intuit-bank-accounts gq-intuit-bank-accounts/get-intuit-bank-accounts
|
||||
:vendor-by-id gq-vendors/get-by-id
|
||||
:account-for-vendor gq-accounts/default-for-vendor
|
||||
:get-user get-user
|
||||
:mutation/delete-transaction-rule gq-transaction-rules/delete-transaction-rule
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||
:test-transaction-rule gq-transaction-rules/test-transaction-rule
|
||||
:run-transaction-rule gq-transaction-rules/run-transaction-rule
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
:mutation/upsert-account gq-accounts/upsert-account
|
||||
:mutation/merge-vendors gq-vendors/merge-vendors
|
||||
:get-vendor gq-vendors/get-graphql
|
||||
:search-vendor gq-vendors/search
|
||||
|
||||
@@ -18,11 +18,6 @@
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
|
||||
(defn get-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [args (assoc args :id (:id context))
|
||||
[accounts accounts-count ] (d-accounts/get-graphql (<-graphql args))]
|
||||
(result->page accounts accounts-count :accounts args)))
|
||||
|
||||
(defn get-all-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
@@ -35,63 +30,6 @@
|
||||
(let [result (d-accounts/get-for-vendor (:vendor_id args) (:client_id args))]
|
||||
(->graphql (d-accounts/clientize result (:client_id args)))))
|
||||
|
||||
(defn upsert-account [context args _]
|
||||
(let [{{:keys [id client-overrides numeric-code location applicability account-set name invoice-allowance vendor-allowance type]} :account} (<-graphql args)]
|
||||
(when-not id
|
||||
(when (seq (dc/q {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
:where ['[?e :account/account-set ?account-set]
|
||||
'[?e :account/numeric-code ?numeric-code]]}
|
||||
(dc/db conn) account-set numeric-code))
|
||||
|
||||
(throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code)
|
||||
{} ))))
|
||||
(let [result (audit-transact [[:upsert-entity
|
||||
(cond-> {:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/search-terms name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/applicability (or (enum->keyword applicability "account-applicability")
|
||||
:account-applicability/global)
|
||||
:account/invoice-allowance (some-> invoice-allowance (enum->keyword "allowance"))
|
||||
:account/vendor-allowance (some-> vendor-allowance (enum->keyword "allowance"))
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/account-set account-set
|
||||
:account/location location
|
||||
:account/numeric-code numeric-code
|
||||
:account/code (str numeric-code)
|
||||
:account/client-overrides (mapv
|
||||
(fn [client-override]
|
||||
{:db/id (or (:id client-override) (random-tempid))
|
||||
:account-client-override/client (:client-id client-override)
|
||||
:account-client-override/name (:name client-override)
|
||||
:account-client-override/search-terms (:name client-override)})
|
||||
client-overrides)}
|
||||
id (dissoc :account/numeric-code :account/code))]]
|
||||
(:id context))
|
||||
updated-account (d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))]
|
||||
(mu/log ::account-updated :account updated-account)
|
||||
(solr/index-documents-raw solr/impl
|
||||
"accounts"
|
||||
(into [{"id" (:db/id updated-account)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account/name updated-account)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (clojure.core/name (:account/applicability updated-account))}]
|
||||
(for [o (:account/client-overrides updated-account)]
|
||||
{"id" (:db/id o)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account-client-override/name o)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (clojure.core/name (:account/applicability updated-account))
|
||||
"client_id" (:db/id (:account-client-override/client o))
|
||||
"account_client_override_id" (:db/id o)}))
|
||||
)
|
||||
(->graphql
|
||||
updated-account))))
|
||||
|
||||
(def search-pattern [:db/id
|
||||
:account/numeric-code
|
||||
:account/location
|
||||
@@ -207,17 +145,3 @@
|
||||
"numeric_code" (:account/numeric-code result)
|
||||
"location" (:account/location result)
|
||||
"applicability" (name (:db/ident (:account/applicability result)))})))
|
||||
|
||||
#_(dc/transact conn
|
||||
[{:db/ident :account-client-override/k2
|
||||
:db/valueType :db.type/tuple
|
||||
:db/tupleAttrs [:account/_client-overrides :account-client-override/client ]
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/unique :db.unique/identity}])
|
||||
|
||||
#_(dc/q '[:find ?o
|
||||
:where [_ :account-client-override/k ?o]]
|
||||
(dc/db conn))
|
||||
|
||||
|
||||
#_(dc/pull (dc/db conn) '[*] [:db/ident :account-client-override/k])
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
(ns auto-ap.graphql.users
|
||||
(:require [auto-ap.datomic :refer [audit-transact]]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin]]))
|
||||
|
||||
(def role->datomic-role {:none :user-role/none
|
||||
:admin :user-role/admin
|
||||
:power_user :user-role/power-user
|
||||
:manager :user-role/manager
|
||||
:user :user-role/user})
|
||||
|
||||
(defn edit-user [context {:keys [edit_user]} _]
|
||||
(assert-admin (:id context))
|
||||
(let [user (d-users/get-by-id (:id edit_user))
|
||||
new-clients (set (map #(Long/parseLong %) (:clients edit_user)))
|
||||
clients-to-remove (->> (:user/clients user)
|
||||
(map :db/id)
|
||||
(filter #(not (new-clients %)) ))]
|
||||
|
||||
|
||||
(audit-transact (-> [{:db/id (:db/id user)
|
||||
:user/role (role->datomic-role (:role edit_user))
|
||||
:user/clients new-clients}]
|
||||
(into (map (fn [c] [:db/retract (:db/id user) :user/clients c]) clients-to-remove)))
|
||||
(:id context))
|
||||
(->graphql
|
||||
(d-users/get-by-id (:id edit_user)))))
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
:refer [add-sorter-fields
|
||||
apply-pagination
|
||||
apply-sort-3
|
||||
audit-transact
|
||||
conn
|
||||
merge-query
|
||||
pull-many
|
||||
@@ -11,6 +12,7 @@
|
||||
[auto-ap.query-params :as query-params]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.grid-page-helper :as helper]
|
||||
@@ -31,6 +33,7 @@
|
||||
[malli.core :as mc]
|
||||
[ring.middleware.nested-params :refer [wrap-nested-params]]))
|
||||
|
||||
;; TODO support for new account
|
||||
(defn filters [request]
|
||||
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
|
||||
"hx-get" (bidi/path-for ssr-routes/only-routes
|
||||
@@ -168,13 +171,33 @@
|
||||
(def table* (partial helper/table* grid-page))
|
||||
|
||||
(defn account-edit-save [{:keys [params route-params] :as request}]
|
||||
(let [_ @(dc/transact conn [[:upsert-entity (-> params (assoc :db/id (:db/id route-params)) (dissoc :id))]])
|
||||
new-account (some-> route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]
|
||||
|
||||
(let [_ (audit-transact [[:upsert-entity (-> params (assoc :db/id (:db/id route-params)) (dissoc :id))]]
|
||||
(:identity request))
|
||||
updated-account (some-> route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]
|
||||
|
||||
(solr/index-documents-raw solr/impl
|
||||
"accounts"
|
||||
(into [{"id" (:db/id updated-account)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account/name updated-account)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (clojure.core/name (:account/applicability updated-account))}]
|
||||
(for [o (:account/client-overrides updated-account)]
|
||||
{"id" (:db/id o)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account-client-override/name o)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (clojure.core/name (:account/applicability updated-account))
|
||||
"client_id" (:db/id (:account-client-override/client o))
|
||||
"account_client_override_id" (:db/id o)}))
|
||||
)
|
||||
|
||||
(html-response
|
||||
(row* identity new-account {:flash? true})
|
||||
(row* identity updated-account {:flash? true})
|
||||
:headers {"hx-trigger" "closeModal"
|
||||
"hx-retarget" (format "#account-table tr[data-id=\"%d\"]" (:db/id new-account))})))
|
||||
"hx-retarget" (format "#account-table tr[data-id=\"%d\"]" (:db/id updated-account))})))
|
||||
|
||||
(defn client-override* [override]
|
||||
[:div.flex.gap-2.mb-2.client-override
|
||||
@@ -194,10 +217,7 @@
|
||||
|
||||
(defn account-edit-dialog [request]
|
||||
(prn (:route-params request))
|
||||
(let [account (some-> request
|
||||
:route-params
|
||||
:db/id
|
||||
(#(dc/pull (dc/db conn) default-read %)))]
|
||||
(let [account (some-> request :route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]
|
||||
(html-response
|
||||
(com/modal
|
||||
{:modal-class "max-w-4xl"}
|
||||
|
||||
Reference in New Issue
Block a user