user progress
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user