merged many changes.
This commit is contained in:
@@ -247,6 +247,7 @@
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id :bank-account/locations :bank-account/current-balance]
|
||||
:transaction/vendor [:db/id :vendor/name]
|
||||
:transaction/matched-rule [:db/id :transaction-rule/note]
|
||||
:transaction/forecast-match [:db/id :forecasted-transaction/identifier]
|
||||
:transaction/accounts [:transaction-account/amount
|
||||
:db/id
|
||||
:transaction-account/location
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
:user
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:role {:type :role}
|
||||
:clients {:type '(list :client)}}}
|
||||
|
||||
:account_client_override
|
||||
@@ -415,7 +415,7 @@
|
||||
:edit_user
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:role {:type :role}
|
||||
:clients {:type '(list String)}}}
|
||||
|
||||
:add_contact
|
||||
@@ -520,6 +520,11 @@
|
||||
:applicability {:values [{:enum-value :global}
|
||||
{:enum-value :optional}
|
||||
{:enum-value :customized}]}
|
||||
:role {:values [{:enum-value :none}
|
||||
{:enum-value :user}
|
||||
{:enum-value :manager}
|
||||
{:enum-value :power_user}
|
||||
{:enum-value :admin}]}
|
||||
:account_type {:values [{:enum-value :dividend}
|
||||
{:enum-value :expense}
|
||||
{:enum-value :asset}
|
||||
|
||||
@@ -2,25 +2,34 @@
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query]]
|
||||
[auto-ap.graphql.utils :refer [assert-admin assert-present <-graphql ->graphql]]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
assert-can-see-client
|
||||
assert-present
|
||||
limited-clients]]
|
||||
[auto-ap.plaid.core :as p]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn plaid-link-token [context value args]
|
||||
(assert-admin (:id context))
|
||||
(when-not (:client_id value)
|
||||
(throw (ex-info "Client ID is required" {:validation-error "Client ID is required"})))
|
||||
(assert-can-see-client (:id context) (:client_id value))
|
||||
(let [client-code (:client/code (d/pull (d/db conn) [:client/code] (:client_id value)))]
|
||||
{:token (p/get-link-token client-code)}))
|
||||
|
||||
(defn link-plaid [context value args]
|
||||
(assert-admin (:id context))
|
||||
(when-not (:client_code value)
|
||||
(throw (ex-info "Client not provided" {:validation-error "Client not provided."})))
|
||||
(when-not (:public_token value)
|
||||
(throw (ex-info "Public token not provided" {:validation-error "public token not provided"})))
|
||||
|
||||
(log/info (:id context) (:db/id (d/pull (d/db conn) [:db/id] [:client/code (:client_code value)])))
|
||||
(assert-can-see-client (:id context) (:db/id (d/pull (d/db conn) [:db/id] [:client/code (:client_code value)])))
|
||||
(let [access-token (:access_token (p/exchange-public-token (:public_token value) (:client_code value)))
|
||||
account-result (p/get-accounts access-token )
|
||||
item {:plaid-item/client [:client/code (:client_code value)]
|
||||
@@ -40,7 +49,8 @@
|
||||
:plaid-item/_accounts "plaid-item"}
|
||||
balance (assoc :plaid-account/balance balance)))))
|
||||
(into [item])))
|
||||
{:message (str "Plaid linked successfully. Access Token: " access-token)}))
|
||||
(log/info "Access token was " access-token)
|
||||
{:message (str "Plaid linked successfully.")}))
|
||||
|
||||
|
||||
(def default-read '[:db/id
|
||||
@@ -54,7 +64,6 @@
|
||||
:plaid-account/name]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(println args)
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where []}
|
||||
@@ -63,6 +72,11 @@
|
||||
(:sort args) (add-sorter-fields {"external-id" ['[?e :plaid-item/external-id ?sort-external-id]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :plaid-item/client ?xx]]}
|
||||
:args [ (set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in '[?client-id]
|
||||
:where ['[?e :plaid-item/client ?client-id]]}
|
||||
@@ -93,7 +107,7 @@
|
||||
|
||||
|
||||
(defn get-plaid-item-page [context args value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [args (assoc args :id (:id context))
|
||||
[plaid-items cnt] (get-graphql (<-graphql (assoc args :id (:id context))))]
|
||||
{:plaid_items (->> plaid-items
|
||||
|
||||
@@ -1,59 +1,49 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require [auto-ap.datomic
|
||||
:refer
|
||||
[audit-transact merge-query remove-nils replace-nils-with-retract uri conn]]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.graphql.utils
|
||||
:refer
|
||||
[->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
ident->enum-f
|
||||
limited-clients
|
||||
result->page
|
||||
snake->kebab]]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[clj-time.coerce :as c])
|
||||
(:import java.time.temporal.ChronoField))
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [audit-transact
|
||||
conn
|
||||
merge-query
|
||||
remove-nils
|
||||
replace-nils-with-retract]]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
ident->enum-f
|
||||
limited-clients
|
||||
result->page
|
||||
snake->kebab]]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
(defn get-transaction-rule-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||
(result->page (->> journal-entries
|
||||
(map (ident->enum-f :transaction-rule/transaction-approval-status)))
|
||||
journal-entries-count :transaction_rules args)))
|
||||
|
||||
(defn get-transaction-rule-matches [context args value]
|
||||
(defn get-transaction-rule-matches [context args _]
|
||||
(if (= "admin" (:user/role (:id context)))
|
||||
(let [all-rules (tr/get-all)
|
||||
transaction (update (d-transactions/get-by-id (:transaction_id args)) :transaction/date coerce/to-date)]
|
||||
transaction (update (d-transactions/get-by-id (:transaction_id args)) :transaction/date c/to-date)]
|
||||
(map ->graphql (rm/get-matching-rules transaction all-rules)))
|
||||
nil))
|
||||
|
||||
(defn deleted-accounts [transaction accounts]
|
||||
(let [current-accounts (:transaction-rule/accounts transaction)
|
||||
specified-ids (->> accounts
|
||||
(map :id)
|
||||
set)
|
||||
existing-ids (->> current-accounts
|
||||
(map :db/id)
|
||||
set)]
|
||||
(set/difference existing-ids specified-ids)))
|
||||
|
||||
(defn transaction-rule-account->entity [{:keys [id account_id percentage location]}]
|
||||
(remove-nils #:transaction-rule-account {:percentage percentage
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location}))
|
||||
|
||||
(defn delete-transaction-rule [context {:keys [transaction_rule_id ]} value]
|
||||
(defn delete-transaction-rule [context {:keys [transaction_rule_id ]} _]
|
||||
(assert-admin (:id context))
|
||||
(let [existing-transaction-rule (tr/get-by-id transaction_rule_id)]
|
||||
(when-not (:transaction-rule/description existing-transaction-rule)
|
||||
@@ -62,10 +52,9 @@
|
||||
(audit-transact [[:db/retractEntity transaction_rule_id]] (:id context))
|
||||
transaction_rule_id))
|
||||
|
||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule :as z} value]
|
||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule} _]
|
||||
(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
||||
_ (when-not (dollars= 1.0 account-total)
|
||||
(let [error (str "Account total (" account-total ") does not reach 100%")]
|
||||
@@ -75,7 +64,7 @@
|
||||
(let [error (str "You must provide a description or a yodlee merchant")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
_ (doseq [a accounts
|
||||
:let [{:keys [:account/location :account/name] :as account} (d/entity (d/db conn) (:account_id a))
|
||||
:let [{:keys [:account/location :account/name]} (d/entity (d/db conn) (:account_id a))
|
||||
client (d/entity (d/db conn) client_id)
|
||||
]]
|
||||
(when (and location (not= location (:location a)))
|
||||
@@ -120,7 +109,7 @@
|
||||
(defn tr [z x]
|
||||
(re-find (re-pattern z) x))
|
||||
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/note :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded? count]
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded? count]
|
||||
(->>
|
||||
(d/query
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
@@ -204,7 +193,7 @@
|
||||
(map ->graphql))
|
||||
conj [])))
|
||||
|
||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte dom_lte dom_gte yodlee_merchant_id]} :transaction_rule :as z} value]
|
||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description client_id bank_account_id amount_lte amount_gte dom_lte dom_gte yodlee_merchant_id]} :transaction_rule} _]
|
||||
(assert-admin id)
|
||||
(-test-transaction-rule id #:transaction-rule {:description description
|
||||
:client (when client_id {:db/id client_id})
|
||||
@@ -217,6 +206,6 @@
|
||||
true 15))
|
||||
|
||||
|
||||
(defn run-transaction-rule [{:keys [id]} {:keys [transaction_rule_id count]} value]
|
||||
(defn run-transaction-rule [{:keys [id]} {:keys [transaction_rule_id count]} _]
|
||||
(assert-admin id)
|
||||
(-test-transaction-rule id (tr/get-by-id transaction_rule_id) false count))
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
[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})
|
||||
(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] :as args} value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
(if (str/includes? q "&")
|
||||
(str "\"" q "\"~0.8")
|
||||
(let [parts (-> q
|
||||
(str/replace #"[\[\]\+\*]" "")
|
||||
(str/replace #"[\[\]\+\*\-]" "")
|
||||
(str/split #"\s+"))
|
||||
exacts (butlast parts)
|
||||
partial (last parts)]
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
|
||||
(add-shutdown-hook! shutdown-mount)
|
||||
(start-server :port 9000 :bind "0.0.0.0" #_#_:handler (cider-nrepl-handler))
|
||||
(alter-var-root #'nrepl.middleware.print/*print-fn* (constantly clojure.pprint/pprint))
|
||||
#_(alter-var-root #'nrepl.middleware.print/*print-fn* (constantly clojure.pprint/pprint))
|
||||
(apply mount/start-without without)))
|
||||
|
||||
(comment
|
||||
|
||||
Reference in New Issue
Block a user