supports filtering down to just duplicates.
This commit is contained in:
@@ -4,33 +4,54 @@
|
||||
[audit-transact audit-transact-batch conn remove-nils]]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.graphql.transaction-rules :as g-tr]
|
||||
[auto-ap.import.transactions :as i-transactions]
|
||||
[auto-ap.graphql.utils
|
||||
:refer
|
||||
[->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
assert-power-user
|
||||
assert-can-see-client
|
||||
assert-power-user
|
||||
enum->keyword
|
||||
ident->enum-f
|
||||
snake->kebab]]
|
||||
[auto-ap.import.transactions :as i-transactions]
|
||||
[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]
|
||||
[auto-ap.datomic.invoices :as d-invoices]))
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||
|
||||
(defn assert-filtered-enough [filters]
|
||||
(when (:potential_duplicates filters)
|
||||
(assert-admin (:id filters))
|
||||
(when-not (:bank_account_id filters)
|
||||
(throw (ex-info "In order to select potential duplicates, you must choose a bank account."
|
||||
{:validation-error "In order to select potential duplicates, you must choose a bank account."})))
|
||||
(when-not (seq (->> filters
|
||||
(filter (fn [[k v]]
|
||||
(not (nil? v))))
|
||||
(filter (comp (complement #{:id :start :sort :client_id :bank_account_id :potential_duplicates :per_page})
|
||||
first))
|
||||
(filter (fn [[k v]]
|
||||
(if (= :date_range k)
|
||||
(and (some? (:start v))
|
||||
(some? (:end v)))
|
||||
true)))))
|
||||
(throw (ex-info "In order to select potential duplicates, you must filter your view more."
|
||||
{:validation-error "In order to select potential duplicates, you must filter your view more."})))))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc (:filters args) :id (:id context))
|
||||
_ (assert-filtered-enough args)
|
||||
[transactions transactions-count] (d-transactions/get-graphql (update (<-graphql args) :approval-status enum->keyword "transaction-approval-status"))
|
||||
transactions (map ->graphql (map approval-status->graphql transactions))]
|
||||
{:data transactions
|
||||
@@ -81,13 +102,16 @@
|
||||
(mapcat (fn [i]
|
||||
(let [transaction (d/entity db i)
|
||||
payment-id (-> transaction :transaction/payment :db/id)
|
||||
expected-deposit-id (-> transaction :transaction/expected-deposit :db/id)]
|
||||
(cond->> [{:db/id i
|
||||
:transaction/approval-status :transaction-approval-status/suppressed}
|
||||
expected-deposit-id (-> transaction :transaction/expected-deposit :db/id)
|
||||
transaction-tx (if (:suppress args)
|
||||
{:db/id i
|
||||
:transaction/approval-status :transaction-approval-status/suppressed}
|
||||
[:db/retractEntity i])]
|
||||
(cond->> [transaction-tx
|
||||
[:db/retractEntity [:journal-entry/original-entity i]]]
|
||||
payment-id (into [{:db/id payment-id
|
||||
:payment/status :payment-status/pending}
|
||||
[:db/retract (:db/id transaction) :transaction/payment payment-id]])
|
||||
:payment/status :payment-status/pending}
|
||||
[:db/retract (:db/id transaction) :transaction/payment payment-id]])
|
||||
expected-deposit-id (into [{:db/id expected-deposit-id
|
||||
:expected-deposit/status :expected-deposit-status/pending}
|
||||
[:db/retract (:db/id transaction) :transaction/expected-deposit expected-deposit-id]]))))
|
||||
@@ -440,3 +464,135 @@
|
||||
conj
|
||||
[]
|
||||
transaction_ids ))
|
||||
|
||||
(def objects
|
||||
{:transaction {:fields {:id {:type :id}
|
||||
:amount {:type 'String}
|
||||
:description_original {:type 'String}
|
||||
:description_simple {:type 'String}
|
||||
:location {:type 'String}
|
||||
:forecast_match {:type :forecast_match}
|
||||
:status {:type 'String}
|
||||
:yodlee_merchant {:type :yodlee_merchant}
|
||||
:client {:type :client}
|
||||
:accounts {:type '(list :invoices_expense_accounts)}
|
||||
:payment {:type :payment}
|
||||
:expected_deposit {:type :expected_deposit}
|
||||
:vendor {:type :vendor}
|
||||
:bank_account {:type :bank_account}
|
||||
:date {:type 'String}
|
||||
:post_date {:type 'String}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:matched_rule {:type :transaction_rule}}}
|
||||
:transaction_page {:fields {:data {:type '(list :transaction)}
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:end {:type 'Int}}}})
|
||||
|
||||
(def queries
|
||||
{:potential_autopay_invoices_matches {:type '(list (list :invoice))
|
||||
:args {:transaction_id {:type :id}}
|
||||
:resolve :get-potential-autopay-invoices-matches}
|
||||
:potential_unpaid_invoices_matches {:type '(list (list :invoice))
|
||||
:args {:transaction_id {:type :id}}
|
||||
:resolve :get-potential-unpaid-invoices-matches}
|
||||
:transaction_page {:type :transaction_page
|
||||
:args {:filters {:type :transaction_filters}}
|
||||
:resolve :get-transaction-page}})
|
||||
|
||||
(def mutations
|
||||
{:bulk_change_transaction_status {:type :message
|
||||
:args {:filters {:type :transaction_filters}
|
||||
:status {:type :transaction_approval_status}
|
||||
:ids {:type '(list :id)}}
|
||||
:resolve :mutation/bulk-change-transaction-status}
|
||||
:delete_transactions {:type :message
|
||||
:args {:filters {:type :transaction_filters}
|
||||
:ids {:type '(list :id)}
|
||||
:suppress {:type 'Boolean}}
|
||||
:resolve :mutation/delete-transactions}
|
||||
:edit_transaction {:type :transaction
|
||||
:args {:transaction {:type :edit_transaction}}
|
||||
:resolve :mutation/edit-transaction}
|
||||
|
||||
:match_transaction {:type :transaction
|
||||
:args {:transaction_id {:type :id}
|
||||
:payment_id {:type :id}}
|
||||
:resolve :mutation/match-transaction}
|
||||
|
||||
:match_transaction_autopay_invoices {:type :transaction
|
||||
:args {:transaction_id {:type :id}
|
||||
:autopay_invoice_ids {:type '(list :id)}}
|
||||
:resolve :mutation/match-transaction-autopay-invoices}
|
||||
|
||||
:match_transaction_unpaid_invoices {:type :transaction
|
||||
:args {:transaction_id {:type :id}
|
||||
:unpaid_invoice_ids {:type '(list :id)}}
|
||||
:resolve :mutation/match-transaction-unpaid-invoices}
|
||||
|
||||
:unlink_transaction {:type :transaction
|
||||
:args {:transaction_id {:type :id}}
|
||||
:resolve :mutation/unlink-transaction}
|
||||
|
||||
:match_transaction_rules {:type '(list :transaction)
|
||||
:args {:transaction_ids {:type '(list :id)}
|
||||
:all {:type 'Boolean}
|
||||
:transaction_rule_id {:type :id}}
|
||||
:resolve :mutation/match-transaction-rules}})
|
||||
|
||||
(def input-objects
|
||||
{:transaction_filters {:fields {:client_id {:type :id}
|
||||
:exact_match_id {:type :id}
|
||||
:import_batch_id {:type :id}
|
||||
:potential_duplicates {:type 'Boolean}
|
||||
:vendor_id {:type :id}
|
||||
:bank_account_id {:type :id}
|
||||
:account_id {:type :id}
|
||||
:date_range {:type :date_range}
|
||||
:location {:type 'String}
|
||||
:amount_lte {:type :money}
|
||||
:amount_gte {:type :money}
|
||||
:description {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:per_page {:type 'Int}
|
||||
:sort {:type '(list :sort_item)}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:unresolved {:type 'Boolean}}}
|
||||
:edit_transaction
|
||||
{:fields {:id {:type :id}
|
||||
:vendor_id {:type :id}
|
||||
:forecast_match {:type :id}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:accounts {:type '(list :edit_expense_account)}}}})
|
||||
|
||||
(def enums
|
||||
{:transaction_approval_status {:values [{:enum-value :approved}
|
||||
{:enum-value :unapproved}
|
||||
{:enum-value :suppressed}
|
||||
{:enum-value :requires_feedback}
|
||||
{:enum-value :excluded}]}})
|
||||
|
||||
(def resolvers
|
||||
{:get-transaction-page get-transaction-page
|
||||
:get-potential-autopay-invoices-matches get-potential-autopay-invoices-matches
|
||||
:get-potential-unpaid-invoices-matches get-potential-unpaid-invoices-matches
|
||||
:mutation/edit-transaction edit-transaction
|
||||
:mutation/unlink-transaction unlink-transaction
|
||||
:mutation/bulk-change-transaction-status bulk-change-status
|
||||
:mutation/delete-transactions delete-transactions
|
||||
:mutation/match-transaction match-transaction
|
||||
:mutation/match-transaction-autopay-invoices match-transaction-autopay-invoices
|
||||
:mutation/match-transaction-unpaid-invoices match-transaction-unpaid-invoices
|
||||
:mutation/match-transaction-rules match-transaction-rules})
|
||||
|
||||
|
||||
(defn attach [schema]
|
||||
(->
|
||||
(merge-with merge schema
|
||||
{:objects objects
|
||||
:queries queries
|
||||
:mutations mutations
|
||||
:input-objects input-objects
|
||||
:enums enums})
|
||||
(attach-resolvers resolvers)))
|
||||
|
||||
Reference in New Issue
Block a user